Kibana version: 7.8.0
Elasticsearch version: 7.8.0
APM Server version: 7.8.0
APM Agent language and version: Java 1.33.0
Browser version: Chrome 103
Is there anything special in your setup? I am trying to write an instrumentation-plugin
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
I am trying to write two instrumentation plugins with the new plugin api (GitHub - elastic/apm-agent-java-plugin-example: Example of instrumentation which plugs in to the Elastic Java Agent and instruments an application) to better monitor our applications.
The first one is a Tibco Messagebus instrumentation which also supports Distributed Tracing (using the OpenTelemetry Propagation of the needed headers as described in the docu). This seems to work ok as far as i can see.
The second on is an instrumentation of the Eclipse Milo library (to connect to an OPC-UA server which is a Parameter Server from one can read value of specific sensors). Standalone this also seems to work great.
But when a request comes in via the message bus (over tibco rv) and then this tries to read a value from the OPC-UA the below Error/stacktrace is thrown.
There seems to be an issues to create a subspan in a span in a propagateted context. But when i analyze the code of the opentelemetry plugin in the agent the stacktrace is pointing to this exact case seems to be already taken care of so it shouldn't even get to this place in the agent-code...
Instrumentation Code:
Code which creates the span in my Eclipse Milo Instrumentation:
Tracer tracer = GlobalOpenTelemetry.get().getTracer("TibcoServer");
Span span = tracer.spanBuilder("OPC.readValue")
.setAttribute("Parameters", ids)
.setSpanKind(SpanKind.CLIENT)
.startSpan();
//return the scope object so that it can be closed in the OnMethodExit method
return span.makeCurrent();
Code which creates the propagated context and coresponding span/transaction in my tibco instrumentation:
Context ctx = GlobalOpenTelemetry.getPropagators()
.getTextMapPropagator()
.extract(Context.current(), message, getter);
Scope extScope = ctx.makeCurrent();
String subject = message.getSendSubject();
// This is the recommended way to obtain the tracer with the Elastic OpenTelemetry bridge
Tracer tracer = GlobalOpenTelemetry.get().getTracer("TibcoServer");
Span span = tracer.spanBuilder(subject)
.setSpanKind(SpanKind.SERVER)
.setAttribute("type", "incoming")
.startSpan();
Provide logs and/or server output (if relevant):
2022-08-01 08:48:44,963 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Activating OTelBridgeContext[{opentelemetry-trace-span-key=PropagatedSpan{ImmutableSpanContext{traceId=f89ec3078b4998153236c89e758eeb4e, spanId=c6062e33fd5df80b, traceFlags=01, traceState=ArrayBasedTraceState{entries=[es, s:1]}, remote=true, valid=true}}}] on thread 32
2022-08-01 08:48:44,974 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e) (1)
2022-08-01 08:48:44,976 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - startTransaction '' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e)
2022-08-01 08:48:44,979 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '***.Development.Gateway.PCS7.Command.getValue' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e) (2)
2022-08-01 08:48:44,981 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Activating OTelBridgeContext[{opentelemetry-trace-span-key=OtelSpan['***.Development.Gateway.PCS7.Command.getValue' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e)]}] on thread 32
2022-08-01 08:48:44,982 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'XFAB.DRS.8Z1.Development.Gateway.PCS7.Command.getValue' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e) (3)
2022/08/01 08:48:44.991 - PID: 7420 - LEVEL: 4 COM - bus - CSysServiceRunnerCallback - Run service in bus thread (synchronous).
2022/08/01 08:48:45.018 - PID: 7420 - LEVEL: 4 COM - bus - CSysRvBusReceiveMessageXF - Received message on subject "***.Development.Gateway.PCS7.Command.getValue" (_INBOX.0A31AFE4.60758AE6233E26.1) from "null": <MESSAGE><CONTENTS type="L" size="1"><PARAMETER type="A">Abluft/Geb35_PFL/2PFL2/L_PFL_202110_PI04/MEAS.V</PARAMETER></CONTENTS></MESSAGE>
2022/08/01 08:48:45.029 - PID: 7420 - LEVEL: 3 ALWAYS - service - CSysPcs7GetValue - Reading Value for Abluft/Geb35_PFL/2PFL2/L_PFL_202110_PI04/MEAS.V
2022-08-01 08:48:45,145 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.Span - startSpan '' 00-36fe412f61d4515688b24da03686d8e7-42ff443191ef965a-01 (20c385b9)
2022-08-01 08:48:45,145 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '***.Development.Gateway.PCS7.Command.getValue' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e) (4)
2022-08-01 08:48:45,145 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '' 00-36fe412f61d4515688b24da03686d8e7-42ff443191ef965a-01 (20c385b9) (1)
2022-08-01 08:48:45,146 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '***.Development.Gateway.PCS7.Command.getValue' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e) (5)
2022-08-01 08:48:45,146 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '***.Development.Gateway.PCS7.Command.getValue' 00-36fe412f61d4515688b24da03686d8e7-0cb7b1098ef73d37-01 (17639f9e) (6)
2022-08-01 08:48:45,146 [Tibrv Dispatcher] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'OPC.readValue' 00-36fe412f61d4515688b24da03686d8e7-42ff443191ef965a-01 (20c385b9) (2)
java.lang.IllegalStateException: unexpected context type to upgrade: co.elastic.apm.agent.opentelemetry.sdk.OTelBridgeContext
at co.elastic.apm.agent.opentelemetry.context.OTelContextStorage.current(OTelContextStorage.java:81)
at io.opentelemetry.context.Context.current(Context.java:91)
at io.opentelemetry.context.ImplicitContextKeyed.makeCurrent(ImplicitContextKeyed.java:33)
at ***.eclipse_milo_apm_plugin.RequestValueInstrumentation$AdviceClass.onEnterHandle(RequestValueInstrumentation.java:62)
...