OpenTelemetry java manual instrumentation without exporter

2.9k Views Asked by At

Currently I am trying to POC OpenTelemetry for a web project (war) and upon reading lots of different documentations I still don't have a proper grasp on some issues, wonder if someone could help pointing out in right direction?

Basically:

1) Is it possible to have OpenTelemetry without any exporter?

I have used the config to do this (OTEL_TRACES_EXPORTER=none, OTEL_METRICS_EXPORTER=none). Would not having any exporter "work"?

2) Do I need to have a span processor in the SdkTracerProvider for Otel to work?

When building the SdkTracerProvider, I wonder if I MUST set a spanProcessor (like BatchSpanProcessor with LoggingSpanExporter) or if since I don't want to use a exporter, just not set a spanProcessor?

To be honest what I am trying to achieve is:

  • NOT to use the agent
  • NOT to use a collector (gateway/local)
  • NOT to use a exporter
  • ONLY In logs (logback) populate spanId and traceId (configured currently with %X{trace_id} and %X{span_id}, but not being populated at the moment, so wonder if have to include also code wise manually in every Log)

Not sure if this is something that is possible.

1

There are 1 best solutions below

3
On BEST ANSWER

I'm able to achieve what you are trying to achieve using below command and latest java agent and Log4j. I'm not seeing any export error and can see trace-id and span id in logs.

java -javaagent:opentelemetry-javaagent.jar \
-Dotel.traces.exporter=none \
-Dotel.metrics.exporter=none \
-Dotel.resource.attributes=service.name=Test-service \
-jar spring-app-0.0.1-SNAPSHOT.jar

Followed Document available here.

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/logger-mdc-instrumentation.md

I'm not sure of MDC part whether it works with manual instrumentation as in the above doc it is mentioned about java agent.