Skip to content
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

fix(tracing): actually set the tracing options in the root context #5118

Merged
merged 12 commits into from
Jul 5, 2023

Conversation

JGAntunes
Copy link
Contributor

@JGAntunes JGAntunes commented Jul 3, 2023

🎉 Thanks for submitting a pull request! 🎉

Summary

Follow up to #5100. This time I actually tested the whole flow e2e:


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@JGAntunes JGAntunes self-assigned this Jul 3, 2023
@JGAntunes JGAntunes force-pushed the fix/trace-properties-handover branch from 1f4e0f0 to d5c81a2 Compare July 3, 2023 17:08
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@@ -1,6 +1,5 @@
import { HoneycombSDK } from '@honeycombio/opentelemetry-node'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HoneycombSDK provides a couple of things out the box which make the initialisation simpler.

@@ -43,7 +43,7 @@ export const startTracing = function (options: TracingOptions, logger: (...args:

// Sets the current trace ID and span ID based on the options received
// this is used as a way to propagate trace context from Buildbot
trace.setSpanContext(context.active(), {
return trace.setSpanContext(context.active(), {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual change that ensures the traceId and spanId are using when initialising the first span.

Comment on lines +77 to +78
// If there's no `coreStepId` then this is a plugin execution
const spanName = `run-step-${coreStepId || 'plugin'}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coreStepId only exists for internal steps. We replace this for plugin for plugin executions and we can use the package_name to aggregate on the package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind giving more information about the plugin vs steps?

For example in this comment, it mentions we have core steps, build commands or plugin. I understand the meaning of the steps we do in buildbot, but not in here. Maybe this is a question too broad, so we can catch up on "Making Moves"

Comment on lines +100 to +101
// tracing.apiKey defaults to '-' else we'll get warning logs if not using
// honeycomb directly - https://github.com/honeycombio/honeycomb-opentelemetry-node/issues/201
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honeycomb emits a set of console.warn logs we can't skip if we don't provide an apiKey - honeycombio/honeycomb-opentelemetry-node#201. This is why for production we pass -, since we're going to use a collector.

serviceName: ROOT_PACKAGE_JSON.name,
traceExporter,
instrumentations: [new HttpInstrumentation()],
protocol: 'grpc',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both in prod and locally we'll always use grpc

import { context, trace, propagation, SpanStatusCode, diag, DiagLogLevel, DiagLogger } from '@opentelemetry/api'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't manage to setup auto instrumentation. Seems like it's now working for esm but it's fairly recent and requires us to pass additional node flags:

I've been thinking a bit about this and I think in the future we might want to have this tracing initialisation happen in a separate module we can use via node --require @netlify/tracing-initialisation ./call-neltify/build (or node --import once we move to node 20 I believe?) since it would:

@JGAntunes JGAntunes marked this pull request as ready for review July 4, 2023 17:12
@JGAntunes JGAntunes requested review from a team as code owners July 4, 2023 17:12
@JGAntunes JGAntunes force-pushed the fix/trace-properties-handover branch from 750837c to edf7b83 Compare July 4, 2023 17:12
@@ -37,9 +37,9 @@ export const startBuild = function (flags: Partial<BuildFlags>) {

const { bugsnagKey, tracingOpts, debug, systemLogFile, ...flagsA } = normalizeFlags(flags, logs)
const errorMonitor = startErrorMonitor({ flags: { tracingOpts, debug, systemLogFile, ...flagsA }, logs, bugsnagKey })
startTracing(tracingOpts, getSystemLogger(logs, debug, systemLogFile))
const rootTracingContext = startTracing(tracingOpts, getSystemLogger(logs, debug, systemLogFile))
Copy link
Contributor

@4xposed 4xposed Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be: rootTrace? is "Context" a thing in the JS/TS world?
scratch that, I just saw the context bit on the other file

Copy link
Contributor Author

@JGAntunes JGAntunes Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context in this case is specifc to the open-telemetry JS implementation. In this case we're returning a context from:

  • // Sets the current trace ID and span ID based on the options received
    // this is used as a way to propagate trace context from Buildbot
    return trace.setSpanContext(context.active(), {
    traceId: options.traceId,
    spanId: options.parentSpanId,
    traceFlags: options.traceFlags,
    isRemote: true,
    })

See:

Also:

This context will hold the specific traceId, spanId, etc. That we pass over from Buildbot.

@kodiakhq kodiakhq bot merged commit 6353314 into main Jul 5, 2023
@kodiakhq kodiakhq bot deleted the fix/trace-properties-handover branch July 5, 2023 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants