Skip to content

Commit bbae2cf

Browse files
committed
fix(server-utils): Set client span kind on direct dataloader ops, not batch
1 parent 9c88b56 commit bbae2cf

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/dataloader
  • packages/server-utils/src/integrations/tracing-channel

dev-packages/node-integration-tests/suites/tracing/dataloader/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ describe('dataloader auto-instrumentation', () => {
2929
expect(loadSpan?.status).toBe('ok');
3030
expect(loadSpan?.data?.['sentry.origin']).toBe(ORIGIN);
3131
expect(loadSpan?.data?.['sentry.op']).toBe(CACHE_GET_OP);
32+
// A direct operation is a client call; the deferred `batch` below gets no kind
33+
expect(loadSpan?.data?.['otel.kind']).toBe('CLIENT');
3234

3335
const batchSpan = spans.find(span => span.description === 'dataloader.batch');
3436
expect(batchSpan).toBeDefined();
3537
expect(batchSpan?.op).toBe(CACHE_GET_OP);
3638
expect(batchSpan?.origin).toBe(ORIGIN);
3739
expect(batchSpan?.status).toBe('ok');
40+
expect(batchSpan?.data?.['otel.kind']).toBeUndefined();
3841

3942
// The batch span links back to the load span that triggered it
4043
expect(batchSpan?.links).toEqual([

packages/server-utils/src/integrations/tracing-channel/dataloader.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ function makeSpanOptions(loader: DataLoaderInstance | undefined, operation: Oper
6666

6767
return {
6868
name: getSpanName(loader, operation),
69-
// The batch runs off a deferred tick and has no obvious network peer, so only `load`/`loadMany`
70-
// get a client kind, matching the vendored OTel instrumentation.
71-
kind: operation === 'batch' ? SPAN_KIND.CLIENT : undefined,
69+
// Every direct operation (`load`/`loadMany`/`prime`/`clear`/`clearAll`) is a client call, matching
70+
// the vendored OTel instrumentation. The `batch` runs off a deferred tick with no obvious network
71+
// peer, so it gets no kind.
72+
kind: operation === 'batch' ? undefined : SPAN_KIND.CLIENT,
7273
op: isCacheGet ? CACHE_GET_OP : undefined,
7374
onlyIfParent: true,
7475
attributes: {

0 commit comments

Comments
 (0)