@@ -48,15 +48,21 @@ OptInAttrs = [{?HTTP_REQUEST_BODY_SIZE, true}]`
4848opentelemetry_cowboy:setup(#{opt_in_attrs => OptInAttrs)
4949```
5050
51+ #### Request and Response Headers as Opt-in Attributes
52+
5153Request and response header attributes are opt-in and can be set with the
5254`request_headers` and `response_headers` options. Values should be lower-case.
5355
56+ ```
57+ opentelemetry_cowboy:setup(#{request_headers => ["x-customer-id"]})
58+ ```
59+
5460### Public Endpoint
5561
5662Setting an endpoint as public will result in any propagated trace to be added as a link,
5763rather than a continuation of an existing trace. The `public_endpoint` option should be set
5864to `true` if an endpoint only accepts public traffic to prevent missing root spans. By default,
59- the endpoint is handled as non-public, resulting in traces being continued rather than linked.
65+ the endpoint is handled as non-public, resulting in traces being continued rather than linked.
6066
6167In a mixed traffic environment, an MFA can be supplied to determine whether to
6268treat a request as public. This function is executed on every request, so refrain
@@ -118,7 +124,7 @@ setup(Opts) when is_list(Opts) ->
118124 setup (maps :from_list (Opts ));
119125setup (Opts ) ->
120126 InitialConfig = maps :merge (default_opts (), Opts ),
121- OptInAttrs = lists :filtermap (fun ({Name , OptedIn }) ->
127+ OptInAttrs = lists :filtermap (fun ({Name , OptedIn }) ->
122128 case OptedIn of
123129 true -> {true , Name };
124130 false -> false end
@@ -162,7 +168,7 @@ extract_headers(Headers, Keys) ->
162168set_req_header_attrs (Attrs , _ReqHeaders , #{request_headers := []}) -> Attrs ;
163169set_req_header_attrs (Attrs , ReqHeaders , #{request_headers := HeadersAttrs }) ->
164170 maps :merge (Attrs , otel_http :extract_headers_attributes (request , ReqHeaders , HeadersAttrs )).
165-
171+
166172set_resp_header_attrs (Attrs , _RespHeaders , #{response_headers := []}) -> Attrs ;
167173set_resp_header_attrs (Attrs , RespHeaders , #{response_headers := HeadersAttrs }) ->
168174 maps :merge (Attrs , otel_http :extract_headers_attributes (response , RespHeaders , HeadersAttrs )).
@@ -251,7 +257,7 @@ ip_to_binary(IP) ->
251257is_public_endpoint (_Req , #{public_endpoint := true }) -> true ;
252258is_public_endpoint (Req , #{public_endpoint_fn := {M , F , A }}) ->
253259 apply (M , F , [Req , A ]).
254-
260+
255261default_public_endpoint_fn (_ , _ ) -> false .
256262
257263opt_in_attrs () ->
@@ -297,8 +303,8 @@ handle_event([cowboy, request, start], _Measurements, #{req := Req} = Meta, Conf
297303 Attrs4 = set_server_address_attrs (Attrs3 , ReqHeaders , Config ),
298304 Attrs5 = set_req_header_attrs (Attrs4 , ReqHeaders , Config ),
299305 AttrsFinal = maps :merge (Attrs5 , maps :filter (fun (K ,_V ) -> lists :member (K , OptedInAttrs ) end , OptInAttrs )),
300-
301- SpanName =
306+
307+ SpanName =
302308 case Method of
303309 ? HTTP_REQUEST_METHOD_VALUES_OTHER ->
304310 'HTTP' ;
@@ -398,7 +404,7 @@ handle_event([cowboy, request, exception], Measurements, Meta, Config) ->
398404 ? HTTP_RESPONSE_BODY_SIZE => RespBodyLength
399405 },
400406 StatusCode = transform_status_to_code (Status ),
401- ErrorType =
407+ ErrorType =
402408 case Reason of
403409 R when is_atom (R ) ->
404410 otel_span :record_exception (Ctx , Kind , Reason , Stacktrace , []),
@@ -419,7 +425,7 @@ handle_event([cowboy, request, exception], Measurements, Meta, Config) ->
419425 otel_span :set_attributes (Ctx , FinalAttrs ),
420426
421427 otel_span :set_status (Ctx , opentelemetry :status (? OTEL_STATUS_ERROR , <<" " >>)),
422-
428+
423429 otel_telemetry :end_telemetry_span (? TRACER_ID , Meta ),
424430 otel_ctx :clear ();
425431
@@ -435,7 +441,7 @@ handle_event([cowboy, request, early_error], Measurements, Meta, Config) ->
435441 resp_headers := RespHeaders ,
436442 resp_status := Status
437443 } = Meta ,
438-
444+
439445 OptInAttrs = #{? HTTP_RESPONSE_BODY_SIZE => RespBodyLength },
440446
441447 StatusCode = transform_status_to_code (Status ),
@@ -478,7 +484,7 @@ set_network_protocol_attrs(Attrs, ReqVersion) ->
478484 ? NETWORK_PROTOCOL_VERSION => Version
479485 })
480486 end .
481-
487+
482488extract_network_protocol (Version ) ->
483489 case Version of
484490 'HTTP/1.0' -> {http , '1.0' };
0 commit comments