Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(otel): Add base SentryPropagator class (#6109)
- Loading branch information
1 parent
0595ee8
commit e00de10
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}); | ||
}); |