Skip to content

Commit

Permalink
feat(otel): Add base SentryPropagator class (#6109)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Nov 2, 2022
1 parent 0595ee8 commit e00de10
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/opentelemetry-node/src/constants.ts
@@ -0,0 +1,3 @@
export const SENTRY_TRACE_HEADER = 'sentry-trace';

export const SENTRY_BAGGAGE_HEADER = 'baggage';
1 change: 1 addition & 0 deletions packages/opentelemetry-node/src/index.ts
@@ -1,3 +1,4 @@
import '@sentry/tracing';

export { SentrySpanProcessor } from './spanprocessor';
export { SentryPropagator } from './propagator';
29 changes: 29 additions & 0 deletions packages/opentelemetry-node/src/propagator.ts
@@ -0,0 +1,29 @@
import { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';

import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER } from './constants';

/**
* Injects and extracts `sentry-trace` and `baggage` headers from carriers.
*/
export class SentryPropagator implements TextMapPropagator {
/**
* @inheritDoc
*/
public inject(_context: Context, _carrier: unknown, _setter: TextMapSetter): void {
// no-op
}

/**
* @inheritDoc
*/
public extract(context: Context, _carrier: unknown, _getter: TextMapGetter): Context {
return context;
}

/**
* @inheritDoc
*/
public fields(): string[] {
return [SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER];
}
}
10 changes: 10 additions & 0 deletions packages/opentelemetry-node/test/propagator.test.ts
@@ -0,0 +1,10 @@
import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER } from '../src/constants';
import { SentryPropagator } from '../src/propagator';

describe('SentryPropagator', () => {
const propogator = new SentryPropagator();

it('returns fields set', () => {
expect(propogator.fields()).toEqual([SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER]);
});
});

0 comments on commit e00de10

Please sign in to comment.