evanderkoogh / otel-cf-workers

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

Add extra resource attributes to config #127

Open oxcafedead opened 2 months ago

oxcafedead commented 2 months ago

Currently, there is no API to insert custom resource attributes.\ For example, to set deployment.environment semantic attribute from OpenTelemetry Semantic Conventions, one has to do smth like:

        postProcessor: (spans) => {
            if (spans.length == 0) {
                return spans;
            }
            const resource = spans[0].resource;
            resource.attributes['deployment.environment'] = env.ENV_NAME;
            return spans;
        }

Ideally, would go great to have it configurable

As I am not sure about proper naming / place to put this -- feel free to throw it away or change, but the overall idea is:

    return {
        exporter: {
            url: tracesEndpoint,
        },
        service: {
            name: serviceName,
            version: env.VERSION,
        },
                extraResourceAttributes: parseAttributes(env.OTEL_ATTRS)),
...

Also not sure if we should update readme as this is not an essential config part.