Skip to content

feat(otel): Add base SentryPropagator class #6109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/opentelemetry-node/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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]);
});
});