Skip to content

Conversation

@JakeChampion
Copy link
Contributor

  • Added package.json for @netlify/otel with necessary dependencies and scripts.
  • Implemented createTracerProvider function to set up tracing within bootstrap
  • Created NetlifySpanExporter class for exporting spans the spans to the console
  • Defined constants for tracer retrieval and shutdown outside the bootstrap
  • exports getTracer and shutdownTracers functions for use inside other packages
  • Wrote tests for getTracer and shutdownTracers functionalities.

… span exporter

- Added package.json for @netlify/otel with necessary dependencies and scripts.
- Implemented createTracerProvider function to set up tracing within bootstrap
- Created NetlifySpanExporter class for exporting spans the spans to the console
- Defined constants for tracer retrieval and shutdown outside the bootstrap
- exports getTracer and shutdownTracers functions for use inside other packages
- Wrote tests for getTracer and shutdownTracers functionalities.
configurable: true,
writable: false,
value: async () => {
return await nodeTracerProvider.shutdown()
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 will be used to shutdown the open telemetry provider at the end of an invocation, thereby ensuring the lambda instance can be used again in the future without retaining any tracing information from the previous invocation -- this enables us to activate tracing for a single request and not all future requests to the same lambda instance

@@ -0,0 +1,2 @@
export const GET_TRACER = Symbol('getTracer')
Copy link
Member

Choose a reason for hiding this comment

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

Do we not need Symbol.for here? If I understand correctly, we'll have two instances of @netlify/otel: one inline into serverless-functions-api and the other one loaded as a dependency from user code. I think Symbol("getTracer") will map to two different symbols, whereas Symbol.for("getTracer") would point to the same one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's true, perhaps we should just use a string instead of adding to the global symbol registry

Copy link
Member

Choose a reason for hiding this comment

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

Works for me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

import { GET_TRACER, SHUTDOWN_TRACERS } from './constants.js';

export const getTracer = async (name?: string, version?: string): Promise<SugaredTracer | undefined> => {
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

To avoid using @ts-ignore, in other places I did this:

const requestContext = (globalThis as GlobalScope).Netlify?.context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, updated to use similar approach

siteId: string,
siteName: string,
}) => {
if (options.headers.has('x-nf-enable-tracing')) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would flip this and early-return here, to avoid having everything nested under this statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

eduardoboucas
eduardoboucas previously approved these changes May 12, 2025
return
}

console.log('__nfOTLPTrace', NetlifySpanExporter.#decoder.decode(JsonTraceSerializer.serializeRequest(spans)))
Copy link
Member

@eduardoboucas eduardoboucas May 12, 2025

Choose a reason for hiding this comment

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

nit: We could move __nfOTLPTrace to the constants file.

}

export const shutdownTracers = async (): Promise<void> => {
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this?

@JakeChampion JakeChampion enabled auto-merge (squash) May 12, 2025 12:44
@JakeChampion JakeChampion merged commit 4056cc4 into main May 12, 2025
23 checks passed
@JakeChampion JakeChampion deleted the jake/otel branch May 12, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants