@@ -168,7 +168,7 @@ def set_fates(clotho, lachesis, atropos, father="Zues", mother="Themis"):
168
168
import logging
169
169
import re
170
170
from functools import wraps
171
- from typing import TYPE_CHECKING , Dict , Optional , Pattern , Type
171
+ from typing import TYPE_CHECKING , Dict , List , Optional , Pattern , Type
172
172
173
173
import attr
174
174
@@ -574,59 +574,22 @@ def set_operation_name(operation_name):
574
574
# Injection and extraction
575
575
576
576
577
- @ensure_active_span ("inject the span into a header" )
578
- def inject_active_span_twisted_headers (headers , destination , check_destination = True ):
577
+ @ensure_active_span ("inject the span into a header dict" )
578
+ def inject_header_dict (
579
+ headers : Dict [bytes , List [bytes ]],
580
+ destination : Optional [str ] = None ,
581
+ check_destination : bool = True ,
582
+ ) -> None :
579
583
"""
580
- Injects a span context into twisted headers in-place
584
+ Injects a span context into a dict of HTTP headers
581
585
582
586
Args:
583
- headers (twisted.web.http_headers.Headers)
584
- destination (str) : address of entity receiving the span context. If check_destination
585
- is true the context will only be injected if the destination matches the
586
- opentracing whitelist
587
+ headers: the dict to inject headers into
588
+ destination: address of entity receiving the span context. Must be given unless
589
+ check_destination is False. The context will only be injected if the
590
+ destination matches the opentracing whitelist
587
591
check_destination (bool): If false, destination will be ignored and the context
588
592
will always be injected.
589
- span (opentracing.Span)
590
-
591
- Returns:
592
- In-place modification of headers
593
-
594
- Note:
595
- The headers set by the tracer are custom to the tracer implementation which
596
- should be unique enough that they don't interfere with any headers set by
597
- synapse or twisted. If we're still using jaeger these headers would be those
598
- here:
599
- https://github.com/jaegertracing/jaeger-client-python/blob/master/jaeger_client/constants.py
600
- """
601
-
602
- if check_destination and not whitelisted_homeserver (destination ):
603
- return
604
-
605
- span = opentracing .tracer .active_span
606
- carrier = {} # type: Dict[str, str]
607
- opentracing .tracer .inject (span .context , opentracing .Format .HTTP_HEADERS , carrier )
608
-
609
- for key , value in carrier .items ():
610
- headers .addRawHeaders (key , value )
611
-
612
-
613
- @ensure_active_span ("inject the span into a byte dict" )
614
- def inject_active_span_byte_dict (headers , destination , check_destination = True ):
615
- """
616
- Injects a span context into a dict where the headers are encoded as byte
617
- strings
618
-
619
- Args:
620
- headers (dict)
621
- destination (str): address of entity receiving the span context. If check_destination
622
- is true the context will only be injected if the destination matches the
623
- opentracing whitelist
624
- check_destination (bool): If false, destination will be ignored and the context
625
- will always be injected.
626
- span (opentracing.Span)
627
-
628
- Returns:
629
- In-place modification of headers
630
593
631
594
Note:
632
595
The headers set by the tracer are custom to the tracer implementation which
@@ -635,8 +598,13 @@ def inject_active_span_byte_dict(headers, destination, check_destination=True):
635
598
here:
636
599
https://github.com/jaegertracing/jaeger-client-python/blob/master/jaeger_client/constants.py
637
600
"""
638
- if check_destination and not whitelisted_homeserver (destination ):
639
- return
601
+ if check_destination :
602
+ if destination is None :
603
+ raise ValueError (
604
+ "destination must be given unless check_destination is False"
605
+ )
606
+ if not whitelisted_homeserver (destination ):
607
+ return
640
608
641
609
span = opentracing .tracer .active_span
642
610
@@ -647,38 +615,6 @@ def inject_active_span_byte_dict(headers, destination, check_destination=True):
647
615
headers [key .encode ()] = [value .encode ()]
648
616
649
617
650
- @ensure_active_span ("inject the span into a text map" )
651
- def inject_active_span_text_map (carrier , destination , check_destination = True ):
652
- """
653
- Injects a span context into a dict
654
-
655
- Args:
656
- carrier (dict)
657
- destination (str): address of entity receiving the span context. If check_destination
658
- is true the context will only be injected if the destination matches the
659
- opentracing whitelist
660
- check_destination (bool): If false, destination will be ignored and the context
661
- will always be injected.
662
-
663
- Returns:
664
- In-place modification of carrier
665
-
666
- Note:
667
- The headers set by the tracer are custom to the tracer implementation which
668
- should be unique enough that they don't interfere with any headers set by
669
- synapse or twisted. If we're still using jaeger these headers would be those
670
- here:
671
- https://github.com/jaegertracing/jaeger-client-python/blob/master/jaeger_client/constants.py
672
- """
673
-
674
- if check_destination and not whitelisted_homeserver (destination ):
675
- return
676
-
677
- opentracing .tracer .inject (
678
- opentracing .tracer .active_span .context , opentracing .Format .TEXT_MAP , carrier
679
- )
680
-
681
-
682
618
@ensure_active_span ("get the active span context as a dict" , ret = {})
683
619
def get_active_span_text_map (destination = None ):
684
620
"""
0 commit comments