@@ -18,7 +18,7 @@ groups() ->
18
18
[{functional , [], [configuration , span_round_trip , ets_instrumentation_info ]},
19
19
{grpc , [], [verify_export , verify_metrics_export ]},
20
20
{grpc_gzip , [], [verify_export ]},
21
- {http_protobuf , [], [verify_export ]},
21
+ {http_protobuf , [], [verify_export , user_agent ]},
22
22
{http_protobuf_gzip , [], [verify_export ]}].
23
23
24
24
init_per_suite (Config ) ->
@@ -520,3 +520,45 @@ verify_export(Config) ->
520
520
? assertMatch (ok , opentelemetry_exporter :export (traces , Tid , Resource , State )),
521
521
522
522
ok .
523
+
524
+ user_agent (Config ) ->
525
+ Protocol = ? config (protocol , Config ),
526
+ Compression = ? config (compression , Config ),
527
+ Port = 4318 ,
528
+
529
+ {ok , State } = opentelemetry_exporter :init (#{protocol => Protocol ,
530
+ compression => Compression ,
531
+ endpoints => [{http , " localhost" , Port , []}]}),
532
+
533
+ Tid = ets :new (span_tab , [duplicate_bag , {keypos , # span .instrumentation_scope }]),
534
+
535
+ TraceId = otel_id_generator :generate_trace_id (),
536
+ SpanId = otel_id_generator :generate_span_id (),
537
+
538
+ ParentSpan =
539
+ # span {name = <<" span-1" >>,
540
+ trace_id = TraceId ,
541
+ span_id = SpanId ,
542
+ kind = ? SPAN_KIND_CLIENT ,
543
+ start_time = opentelemetry :timestamp (),
544
+ end_time = opentelemetry :timestamp (),
545
+ status = # status {code = ? OTEL_STATUS_UNSET , message = <<" hello I'm unset" >>},
546
+ links = otel_links :new ([], 128 , 128 , 128 ),
547
+ events = otel_events :new (128 , 128 , 128 ),
548
+ instrumentation_scope = # instrumentation_scope {name = <<" tracer-1" >>,
549
+ version = <<" 0.0.1" >>},
550
+ attributes = otel_attributes :new ([{<<" attr-2" >>, <<" value-2" >>}], 128 , 128 )},
551
+ true = ets :insert (Tid , ParentSpan ),
552
+ Resource = otel_resource_env_var :get_resource ([]),
553
+
554
+ meck :new (httpc ),
555
+ meck :expect (httpc , request , fun (post , {_ , Headers , " application/x-protobuf" , _ }, _ , _ , _ ) ->
556
+ {_ , UserAgent } = lists :keyfind (" User-Agent" , 1 , Headers ),
557
+ {ok , ExporterVsn } = application :get_key (opentelemetry_exporter , vsn ),
558
+ ExpectedUserAgent = lists :flatten (io_lib :format (" OTel-OTLP-Exporter-erlang/~s " , [ExporterVsn ])),
559
+ ? assertEqual (ExpectedUserAgent , UserAgent ),
560
+ {ok , {{" 1.1" , 200 , " " }, [], <<>>}}
561
+ end ),
562
+ ? assertMatch (ok , opentelemetry_exporter :export (traces , Tid , Resource , State )),
563
+ ? assert (meck :validate (httpc )),
564
+ meck :unload (httpc ).
0 commit comments