-
Notifications
You must be signed in to change notification settings - Fork 85
fix(tracing): handle buildbot tracing integration problems #5100
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { HoneycombSDK } from '@honeycombio/opentelemetry-node' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't really need the HoneycombSDK since we're using a collector. Plus it was logging warnings I couldn't supress: |
||
| import { context, trace, propagation, SpanStatusCode } from '@opentelemetry/api' | ||
| import { context, trace, propagation, SpanStatusCode, diag, DiagLogLevel, DiagLogger } from '@opentelemetry/api' | ||
| import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' | ||
| import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' | ||
| import { NodeSDK } from '@opentelemetry/sdk-node' | ||
|
|
||
|
|
@@ -8,17 +8,37 @@ import { ROOT_PACKAGE_JSON } from '../utils/json.js' | |
|
|
||
| let sdk: NodeSDK | ||
|
|
||
| /** Given a simple logging function return a `DiagLogger`. Used to setup our system logger as the diag logger.*/ | ||
| const getOtelLogger = function (logger: (...args: any[]) => void): DiagLogger { | ||
| const otelLogger = (...args: any[]) => logger('[otel-traces]', ...args) | ||
| return { | ||
| debug: otelLogger, | ||
| info: otelLogger, | ||
| error: otelLogger, | ||
| verbose: otelLogger, | ||
| warn: otelLogger, | ||
| } | ||
| } | ||
|
|
||
| /** Starts the tracing SDK, if there's already a tracing service this will be a no-op */ | ||
| export const startTracing = function (options: TracingOptions) { | ||
| export const startTracing = function (options: TracingOptions, logger: (...args: any[]) => void) { | ||
| if (!options.enabled) return | ||
| if (sdk) return | ||
|
|
||
| sdk = new HoneycombSDK({ | ||
| const traceExporter = new OTLPTraceExporter({ | ||
| url: `http://${options.host}:${options.port}`, | ||
| }) | ||
|
|
||
| sdk = new NodeSDK({ | ||
| serviceName: ROOT_PACKAGE_JSON.name, | ||
| endpoint: `http://${options.host}:${options.port}`, | ||
| traceExporter, | ||
| instrumentations: [new HttpInstrumentation()], | ||
| }) | ||
|
|
||
| // Set the diagnostics logger to our system logger. We also need to suppress the override msg | ||
| // in case there's a default console logger already registered (it would log a msg to it) | ||
| diag.setLogger(getOtelLogger(logger), { logLevel: DiagLogLevel.INFO, suppressOverrideMessage: true }) | ||
|
|
||
|
Comment on lines
+38
to
+41
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sets the internal diagnostics logger for open telemetry to our system logger. Running this locally renders something like this if there's any errors and we're running in debug mode (in Buildbot prod this should still land in our backend without showing up in customer's builds): Removing the |
||
| sdk.start() | ||
|
|
||
| // Sets the current trace ID and span ID based on the options received | ||
|
|
@@ -34,7 +54,13 @@ export const startTracing = function (options: TracingOptions) { | |
| /** Stops the tracing service if there's one running. This will flush any ongoing events */ | ||
| export const stopTracing = async function () { | ||
| if (!sdk) return | ||
| return sdk.shutdown() | ||
| try { | ||
| // The shutdown method might return an error if we fail to flush the traces | ||
| // We handle it and use our diagnostics logger | ||
| await sdk.shutdown() | ||
| } catch (e) { | ||
| diag.error(e) | ||
| } | ||
| } | ||
|
|
||
| /** Sets attributes to be propagated across child spans under the current context */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually perform the transformation and apply the default values to
tracingOptsπ€· this makes sure we use that.