-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import OpenTelemetry types rather than duplicate (#659)
Use Typescript's `import type` and `export type` to include the OpenTelemetry types into our package without having to copy the code into our project directly. This was suggested by @unflxw in PR #651 (comment) I'm not sure if this is more or less fragile. If the OpenTelemetry package changes the interface we'd be shipping an older version that doesn't work with older versions anymore. The package from which we import is a dev dependency only, and used during the compile step, and won't ship as a dependency in the final release. I got an issue when using the OpenTelemetry SpanProcessor type for the `onEnd` function. It doesn't have a second argument. The `onStart` also needed another type, from `SpanContext` to `Context`.
- Loading branch information
Showing
5 changed files
with
128 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...ets/use-opentelemetry-spanprocessor-interface-to-build-our-own-spanprocessor.md
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,6 @@ | ||
--- | ||
bump: "patch" | ||
type: "change" | ||
--- | ||
|
||
Use the OpenTelemetry SpanProcessor interface to build our own SpanProcessor. We previously copied the SpanProcessor code into our package, but instead we now use the OpenTelemetry interface directly. This should make our processor match the expected type better. |
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
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,44 +1,7 @@ | ||
import { HrTime, Span, SpanAttributes, SpanContext } from "@opentelemetry/api" | ||
import type { | ||
Span, | ||
ReadableSpan, | ||
SpanProcessor | ||
} from "@opentelemetry/sdk-trace-base" | ||
|
||
/** | ||
* OpenTelemetrySpanProcessor is based on OpenTelemetry's internal span processor. | ||
*/ | ||
export interface OpenTelemetrySpanProcessor { | ||
/** | ||
* Forces to export all finished spans | ||
*/ | ||
forceFlush(): Promise<void> | ||
|
||
/** | ||
* Called when an OpenTelemetry {@link Span} is started, if the | ||
* `span.isRecording()` returns true. | ||
* @param span the OpenTelemetry Span that just started. | ||
*/ | ||
onStart(_span: Span, _parentContext: SpanContext): void | ||
|
||
/** | ||
* Called when an OpenTelemetry {@link Span} is ended, if the | ||
* `span.isRecording()` returns true. | ||
* @param span the Span that just ended. | ||
*/ | ||
onEnd(_span: ReadableSpan, _parentContext: SpanContext): void | ||
|
||
/** | ||
* Shuts down the processor. Called when the OpenTelemetry SDK is shut down. | ||
* This is an opportunity for processor to do any cleanup required. | ||
*/ | ||
shutdown(): Promise<void> | ||
} | ||
|
||
/** | ||
* ReadableSpan is based on a subset of OpenTelemetry's internal "readable" | ||
* spans, which have readonly attributes for exporting. | ||
*/ | ||
export interface ReadableSpan { | ||
readonly name: string | ||
readonly spanContext: () => SpanContext | ||
readonly startTime: HrTime | ||
readonly endTime: HrTime | ||
readonly attributes: SpanAttributes | ||
readonly instrumentationLibrary: { name: string } | ||
} | ||
export type { Span, ReadableSpan, SpanProcessor } |
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