mirror of
https://github.com/taoensso/telemere.git
synced 2025-12-17 09:51:12 +00:00
[new] [#44] Open Telemetry handler: add span kind option (@farcaller)
This commit is contained in:
parent
db0498b22c
commit
413cce87c3
2 changed files with 16 additions and 5 deletions
|
|
@ -220,17 +220,27 @@
|
||||||
We leave the (expensive) population of attributes, etc. for signal handler.
|
We leave the (expensive) population of attributes, etc. for signal handler.
|
||||||
Interop needs only the basics (t0, traceId, spanId, spanName) right away."
|
Interop needs only the basics (t0, traceId, spanId, spanName) right away."
|
||||||
^io.opentelemetry.context.Context
|
^io.opentelemetry.context.Context
|
||||||
[id inst ?parent-context]
|
[id inst ?parent-context ?span-kind]
|
||||||
(let [parent-context (or ?parent-context (otel-context))]
|
(let [parent-context (or ?parent-context (otel-context))]
|
||||||
(enc/if-not [tracer (force taoensso.telemere/*otel-tracer*)]
|
(enc/if-not [tracer (force taoensso.telemere/*otel-tracer*)]
|
||||||
parent-context ; Can't add Span without Tracer
|
parent-context ; Can't add Span without Tracer
|
||||||
(let [sb (.spanBuilder ^io.opentelemetry.api.trace.Tracer tracer (otel-name id))]
|
(let [sb (.spanBuilder ^io.opentelemetry.api.trace.Tracer tracer (otel-name id))]
|
||||||
(.setStartTimestamp sb ^java.time.Instant inst)
|
(.setStartTimestamp sb ^java.time.Instant inst)
|
||||||
|
(.setSpanKind sb
|
||||||
|
(case ?span-kind
|
||||||
|
(nil :internal) io.opentelemetry.api.trace.SpanKind/INTERNAL
|
||||||
|
:client io.opentelemetry.api.trace.SpanKind/CLIENT
|
||||||
|
:server io.opentelemetry.api.trace.SpanKind/SERVER
|
||||||
|
:consumer io.opentelemetry.api.trace.SpanKind/CONSUMER
|
||||||
|
:producer io.opentelemetry.api.trace.SpanKind/PRODUCER
|
||||||
|
(enc/unexpected-arg! ?span-kind
|
||||||
|
{:expected #{nil :internal :client :server :consumer :producer}})))
|
||||||
|
|
||||||
(.with ^io.opentelemetry.context.Context parent-context
|
(.with ^io.opentelemetry.context.Context parent-context
|
||||||
(.startSpan sb)))))))))
|
(.startSpan sb)))))))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(enc/qb 1e6 (otel-context) (otel-context+span ::id1 (enc/now-inst) nil)) ; [46.42 186.89]
|
(enc/qb 1e6 (otel-context) (otel-context+span ::id1 (enc/now-inst) nil nil)) ; [46.42 186.89]
|
||||||
(viable-tracer (force taoensso.telemere/*otel-tracer*))
|
(viable-tracer (force taoensso.telemere/*otel-tracer*))
|
||||||
(otel-trace-id (otel-context)))
|
(otel-trace-id (otel-context)))
|
||||||
|
|
||||||
|
|
@ -689,9 +699,9 @@
|
||||||
|
|
||||||
;; Trace with OpenTelemetry
|
;; Trace with OpenTelemetry
|
||||||
(and clj? enabled:otel-tracing?)
|
(and clj? enabled:otel-tracing?)
|
||||||
`[~'__otel-context0 ~(get opts :otel/context `(otel-context)) ; Context
|
`[~'__otel-context0 ~(get opts :otel/context `(otel-context)) ; Context
|
||||||
~'__otel-context1 ~(if run-form `(otel-context+span ~'__id ~'__inst ~'__otel-context0) ~'__otel-context0)
|
~'__otel-context1 ~(if run-form `(otel-context+span ~'__id ~'__inst ~'__otel-context0 ~(get opts :otel/span-kind)) ~'__otel-context0)
|
||||||
~'__uid ~(auto-> uid-form `(or (otel-span-id ~'__otel-context1) (com.taoensso.encore.Ids/genHexId16)))
|
~'__uid ~(auto-> uid-form `(or (otel-span-id ~'__otel-context1) (com.taoensso.encore.Ids/genHexId16)))
|
||||||
~'__root1
|
~'__root1
|
||||||
(or ~'__root0
|
(or ~'__root0
|
||||||
~(when trace?
|
~(when trace?
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@
|
||||||
`:otel/attrs` - Attributes [1] to add to log records AND tracing spans/events
|
`:otel/attrs` - Attributes [1] to add to log records AND tracing spans/events
|
||||||
`:otel/log-attrs` - Attributes [1] to add to log records ONLY
|
`:otel/log-attrs` - Attributes [1] to add to log records ONLY
|
||||||
`:otel/trace-attrs` - Attributes [1] to add to tracing spans/events ONLY
|
`:otel/trace-attrs` - Attributes [1] to add to tracing spans/events ONLY
|
||||||
|
`:otel/span-kind` - Span kind ∈ #{:internal (default) :client :server :consumer :producer}
|
||||||
|
|
||||||
[1] `io.opentelemetry.api.common.Attributes` or Clojure map with str/kw keys and vals ∈
|
[1] `io.opentelemetry.api.common.Attributes` or Clojure map with str/kw keys and vals ∈
|
||||||
#{nil boolean keyword string UUID long double string-vec long-vec double-vec boolean-vec}.
|
#{nil boolean keyword string UUID long double string-vec long-vec double-vec boolean-vec}.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue