Преглед изворни кода

fix: attribute_meta_value as required field

JimMoen пре 1 година
родитељ
комит
2df441dac4

+ 2 - 0
apps/emqx_opentelemetry/include/emqx_otel_trace.hrl

@@ -38,6 +38,8 @@
 -define(EMQX_OTEL_SAMPLE_CLIENTID, 1).
 -define(EMQX_OTEL_SAMPLE_TOPIC, 2).
 
+-define(EMQX_OTEL_DEFAULT_META_VALUE, <<"emqxcl">>).
+
 -record(?EMQX_OTEL_SAMPLER, {
     type ::
         {?EMQX_OTEL_SAMPLE_CLIENTID, binary() | '_'}

+ 2 - 0
apps/emqx_opentelemetry/src/emqx_otel_schema.erl

@@ -245,6 +245,8 @@ fields("e2e_tracing_options") ->
             ?HOCON(
                 string(),
                 #{
+                    required => true,
+                    default => ?EMQX_OTEL_DEFAULT_META_VALUE,
                     desc => ?DESC(e2e_attribute_meta_value),
                     importance => ?IMPORTANCE_MEDIUM
                 }

+ 9 - 9
apps/emqx_opentelemetry/src/sampler/emqx_otel_sampler.erl

@@ -174,9 +174,7 @@ should_sample(
     SpanName,
     _SpanKind,
     Attributes,
-    #{
-        attribute_meta_value := MetaValue
-    } = Opts
+    Opts
 ) when
     SpanName =:= ?CLIENT_CONNECT_SPAN_NAME orelse
         SpanName =:= ?CLIENT_DISCONNECT_SPAN_NAME orelse
@@ -189,7 +187,7 @@ should_sample(
             decide_by_traceid_ratio(TraceId, SpanName, Opts),
     {
         decide(Desicion),
-        #{?META_KEY => MetaValue},
+        with_meta_value(Opts),
         otel_span:tracestate(otel_tracer:current_span_ctx(Ctx))
     };
 %% None Root Span, decide by Parent or Publish Response Tracing Level
@@ -200,17 +198,14 @@ should_sample(
     SpanName,
     _SpanKind,
     _Attributes,
-    #{
-        msg_trace_level := QoS,
-        attribute_meta_value := MetaValue
-    } = _Opts
+    #{msg_trace_level := QoS} = Opts
 ) ->
     Desicion =
         parent_sampled(otel_tracer:current_span_ctx(Ctx)) andalso
             match_by_span_name(SpanName, QoS),
     {
         decide(Desicion),
-        #{?META_KEY => MetaValue},
+        with_meta_value(Opts),
         otel_span:tracestate(otel_tracer:current_span_ctx(Ctx))
     }.
 
@@ -308,3 +303,8 @@ decide(true) ->
     ?RECORD_AND_SAMPLE;
 decide(false) ->
     ?DROP.
+
+with_meta_value(#{attribute_meta_value := MetaValue}) ->
+    #{?META_KEY => MetaValue};
+with_meta_value(_) ->
+    #{}.