taoensso / telemere

Structured telemetry library for Clojure/Script
https://www.taoensso.com/telemere
Eclipse Public License 1.0
167 stars 2 forks source link

otlp exporter exception #16

Closed flyingmachine closed 1 month ago

flyingmachine commented 1 month ago

I'm seeing the following logged when I try to log a trace:

[otel.javaagent 2024-08-19 15:32:05:900 -0400] [BatchSpanProcessor_WorkerThread-1] WARN io.opentelemetry.sdk.trace.export.BatchSpanProcessor - Exporter threw an Exception
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long (java.lang.Integer and java.lang.Long are in module java.base of loader 'bootstrap')
at io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler.create(KeyValueMarshaler.java:83)
at io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler.access$000(KeyValueMarshaler.java:28)
at io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler$1.accept(KeyValueMarshaler.java:63)
at io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler$1.accept(KeyValueMarshaler.java:58)
at java.base/java.util.HashMap.forEach(HashMap.java:1337)
at io.opentelemetry.sdk.internal.AttributesMap.forEach(AttributesMap.java:88)
at io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler.createForAttributes(KeyValueMarshaler.java:57)
at io.opentelemetry.exporter.internal.otlp.traces.SpanMarshaler.create(SpanMarshaler.java:46)
at io.opentelemetry.exporter.internal.marshal.MarshalerUtil.groupByResourceAndScope(MarshalerUtil.java:68)
at io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler.groupByResourceAndScope(ResourceSpansMarshaler.java:96)
at io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler.create(ResourceSpansMarshaler.java:37)
at io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler.create(TraceRequestMarshaler.java:32)
at io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter.export(OtlpHttpSpanExporter.java:101)
at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.exportCurrentBatch(BatchSpanProcessor.java:340)
at io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.run(BatchSpanProcessor.java:258)
at java.base/java.lang.Thread.run(Thread.java:829)

I have my project configured to use the otel java agent and to export traces as OTLP. Happy to share more details! Hacking open_telemetry.clj to coerce signal lines to longs seems to remedy it:

(let [ak-uid  (io.opentelemetry.api.common.AttributeKey/stringKey "uid")
      ak-ns   (io.opentelemetry.api.common.AttributeKey/stringKey "ns")
      ak-line (io.opentelemetry.api.common.AttributeKey/longKey   "line")]

  (defn- span-attrs
    "Returns `io.opentelemetry.api.common.Attributes` or nil."
    [uid signal]
    (prn "line" (type (get signal :line)))
    (if uid
      (if-let   [ns   (get signal :ns)]
        (if-let [line (get signal :line)]
          (Attributes/of ak-uid (str uid), ak-ns ns, ak-line (long line))
          (Attributes/of ak-uid (str uid), ak-ns ns))
        (Attributes/of   ak-uid (str uid)))

      (if-let   [ns   (get signal :ns)]
        (if-let [line (get signal :line)]
          (Attributes/of ak-ns ns, ak-line (long line))
          (Attributes/of ak-ns ns))
        nil))))
ptaoussanis commented 1 month ago

@flyingmachine Hey Daniel, thanks a lot for the report (and for identifying the issue!).

Does the OTLP exporter seem to work okay otherwise? If so, I'll cut a new release with your fix first thing tomorrow 👍

flyingmachine commented 1 month ago

Hey Peter! I’m not at my computer at the moment to try this out but the addition of :_otel-context was preventing handle-tracing! from being called, as far as I could tell. Thank you!