Adding metadata to custom exit spans

I'm using java agent 1.42.0 and OTel API 1.32.0.

ECS, as well as the OTel schema, define metadata like destination.address, destination,port, etc. I've created a custom span to track backend calls using the unsupported UnboundId LDAP library and would like to set address and port, as well as a few other values.

My code looks like this:

Span span = GlobalOpenTelemetry.getTracer("").spanBuilder(this.getClass().getName() + "#send").setSpanKind(SpanKind.CLIENT).startSpan();

        span.setAttribute(addressKey, Arrays.toString(getConnector().getConnectionInfo().getServerAddresses()));
        span.setAttribute(portKey, Arrays.toString(getConnector().getConnectionInfo().getServerPorts()));
        span.setAttribute(typeKey, "external");
        span.setAttribute(subtypeKey, "ldap");

try {
  ...
} finally {
  span.end();
}

The keys are static variables of type AttributeKey with strings like "destination.address" etc.

These values show up as labels like "labels.destination_address" but I would like them to not be labels and instead be more like "destination.address" that I see in the OOTB spans.

I suspect this might also have something to do with why this exit call doesn't show in my dependencies list.

thanks

Hi,

Unfortunately as you capture those OTel span attributes there is no way to override the values captured by the agent to make them like the OOTB spans.

For now maybe the best alternative could be to use our agent Public API instead of the OTel one, as this one allows to set the span destination details: Public API | APM Java Agent Reference [1.x] | Elastic

While you could use an ingest pipeline to modify the span documents as they are written by apm-server, that would not modify the related metric documents.

This is definitely something that should be easier to achieve in the future as we are working on it, ideally you should only have to follow the OTel semantic conventions to create a custom span.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.