evanderkoogh / otel-cf-workers

An OpenTelemetry compatible library for instrumenting and exporting traces for Cloudflare Workers
BSD 3-Clause "New" or "Revised" License
239 stars 50 forks source link

faas.execution semantic attribute with CF-Ray #25

Closed rtbenfield closed 1 year ago

rtbenfield commented 1 year ago

Would you be interested in incorporating the CF-Ray header from Cloudflare into the span attributes of fetchHandler? The semantic attributes package offers faas.execution, which seems fitting for this and is what I have used previously. The JSDoc describes the attribute as "The execution ID of the current function execution.".

It's not difficult to add this in userland either, but it's been so successful for correlation with LogPush jobs that I thought incorporating it by default might help others 🙂

const attributes = {
    [SemanticAttributes.FAAS_TRIGGER]: 'http',
    [SemanticAttributes.FAAS_COLDSTART]: cold_start,
+   [SemanticAttributes.FAAS_EXECUTION]: request.headers.get('cf-ray') ?? undefined,
}

I'm happy to raise a PR for this if it would be fitting for the package.

evanderkoogh commented 1 year ago

Absolutely! Put it in!

rtbenfield commented 1 year ago

I also took a quick look at our LogPush logs for queue messages to see if there was an equivalent value to use there. It doesn't look like they are assigned an identifier per invocation. Do you know if there's a value I'm overlooking?

DaniFoldi commented 1 year ago

To my knowledge, there is no way to uniquely identify a non-fetch handler being run, like the cf-ray header on fetch requests. The best would probably be generating a uuid/nanoid/similar.