Skip to content

Commit

Permalink
fix: chcek root span from context
Browse files Browse the repository at this point in the history
  • Loading branch information
DinaYakovlev committed Mar 3, 2021
1 parent 3b09b3d commit 5add4e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
7 changes: 3 additions & 4 deletions plugins/node/opentelemetry-instrumentation-koa/src/koa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ import {
InstrumentationNodeModuleDefinition,
} from '@opentelemetry/instrumentation';

import type * as koa from 'koa';
import * as koa from 'koa';
import {
KoaMiddleware,
KoaContext,
KoaComponentName,
kLayerPatched,
KoaLayerType,
AttributeNames,
KoaPluginSpan,
} from './types';
import { VERSION } from './version';
import { getMiddlewareMetadata } from './utils';
Expand Down Expand Up @@ -128,7 +127,7 @@ export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
middlewareLayer[kLayerPatched] = true;
this._logger.debug('patching Koa middleware layer');
return async (context: KoaContext, next: koa.Next) => {
const parent = api.getSpan(api.context.active()) as KoaPluginSpan;
const parent = api.getSpan(api.context.active());
if (parent === undefined) {
return middlewareLayer(context, next);
}
Expand All @@ -142,7 +141,7 @@ export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
attributes: metadata.attributes,
});

if (!parent?.parentSpanId) {
if (!context.request.ctx.parentSpan) {
context.request.ctx.parentSpan = parent;
}

Expand Down
8 changes: 0 additions & 8 deletions plugins/node/opentelemetry-instrumentation-koa/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import type { Middleware, ParameterizedContext, DefaultState } from 'koa';
import type { RouterParamContext } from '@koa/router';
import type * as Router from '@koa/router';
import type { Span } from '@opentelemetry/api';

/**
* This symbol is used to mark a Koa layer as being already instrumented
Expand All @@ -42,10 +41,3 @@ export enum KoaLayerType {
}

export const KoaComponentName = 'koa';

/**
* extends opentelemetry/api Span object to instrument the root span name of http plugin by getting parent span id
*/
export interface KoaPluginSpan extends Span {
parentSpanId?: string;
}

0 comments on commit 5add4e8

Please sign in to comment.