Skip to content

Allow configuring resource detectors #328

@wolverian

Description

@wolverian

I'd like my traces to contain OS and process info. I'd like to add basically all the detectors available in https://pkg.go.dev/go.opentelemetry.io/otel/sdk/resource. I don't see a way to do that currently.

One option would be to add launcher.WithDetectors(detectors ...Detector) Option to launcher, so you could say:

otelShutdown, err := launcher.ConfigureOpenTelemetry(launcher.WithDetectors(resource.WithHost(), resource.WithOS()))

This might need the launcher.Config type to be changed to carry detectors in it.

Another option would be to allow adding the resource explicitly:

res, err := resource.New(context.Background(), resource.WithOS(), resource.WithProcess())
if err != nil {
    log.Fatalf("could not detect opentelemetry resources: %s", err)
}
otelShutdown, err := launcher.ConfigureOpenTelemetry(launcher.WithResource(res))

I think for now it's possible to work around the issue by serialising the resource into an attribute map:

res, err := resource.New(context.Background(), resource.WithOS(), resource.WithProcess())
if err != nil {
    log.Fatalf("could not detect opentelemetry resources: %s", err)
}
attribs := res.Attributes()
attribMap := make(map[string]string)
for _, attrib := range attribs {
    attribMap[string(attrib.Key)] = attrib.Value.AsString()
}
otelShutdown, err := launcher.ConfigureOpenTelemetry(launcher.WithResourceAttributes(attribMap))

The issue is that this is highly unintuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions