Skip to content

Commit e00de10

Browse files
authored
feat(otel): Add base SentryPropagator class (#6109)
1 parent 0595ee8 commit e00de10

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const SENTRY_TRACE_HEADER = 'sentry-trace';
2+
3+
export const SENTRY_BAGGAGE_HEADER = 'baggage';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import '@sentry/tracing';
22

33
export { SentrySpanProcessor } from './spanprocessor';
4+
export { SentryPropagator } from './propagator';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';
2+
3+
import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER } from './constants';
4+
5+
/**
6+
* Injects and extracts `sentry-trace` and `baggage` headers from carriers.
7+
*/
8+
export class SentryPropagator implements TextMapPropagator {
9+
/**
10+
* @inheritDoc
11+
*/
12+
public inject(_context: Context, _carrier: unknown, _setter: TextMapSetter): void {
13+
// no-op
14+
}
15+
16+
/**
17+
* @inheritDoc
18+
*/
19+
public extract(context: Context, _carrier: unknown, _getter: TextMapGetter): Context {
20+
return context;
21+
}
22+
23+
/**
24+
* @inheritDoc
25+
*/
26+
public fields(): string[] {
27+
return [SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER];
28+
}
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER } from '../src/constants';
2+
import { SentryPropagator } from '../src/propagator';
3+
4+
describe('SentryPropagator', () => {
5+
const propogator = new SentryPropagator();
6+
7+
it('returns fields set', () => {
8+
expect(propogator.fields()).toEqual([SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER]);
9+
});
10+
});

0 commit comments

Comments
 (0)