@@ -24,7 +24,7 @@ class EmbeddingInvocation(GenAIInvocation):
2424 context manager rather than constructing this directly.
2525 """
2626
27- def __init__ ( # pylint: disable=too-many-locals
27+ def __init__ (
2828 self ,
2929 tracer : Tracer ,
3030 metrics_recorder : InvocationMetricsRecorder ,
@@ -35,12 +35,6 @@ def __init__( # pylint: disable=too-many-locals
3535 request_model : str | None = None ,
3636 server_address : str | None = None ,
3737 server_port : int | None = None ,
38- encoding_formats : list [str ] | None = None ,
39- input_tokens : int | None = None ,
40- dimension_count : int | None = None ,
41- response_model_name : str | None = None ,
42- attributes : dict [str , Any ] | None = None ,
43- metric_attributes : dict [str , Any ] | None = None ,
4438 ) -> None :
4539 """Use handler.start_embedding(provider) or handler.embedding(provider) instead of calling this directly."""
4640 _operation_name = GenAI .GenAiOperationNameValues .EMBEDDINGS .value
@@ -54,20 +48,31 @@ def __init__( # pylint: disable=too-many-locals
5448 if request_model
5549 else _operation_name ,
5650 span_kind = SpanKind .CLIENT ,
57- attributes = attributes ,
58- metric_attributes = metric_attributes ,
5951 )
6052 self .provider = provider # e.g., azure.ai.openai, openai, aws.bedrock
6153 self .request_model = request_model
6254 self .server_address = server_address
6355 self .server_port = server_port
6456 # encoding_formats can be multi-value -> combinational cardinality risk.
6557 # Keep on spans/events only.
66- self .encoding_formats = encoding_formats
67- self .input_tokens = input_tokens
68- self .dimension_count = dimension_count
69- self .response_model_name = response_model_name
70- self ._start ()
58+ self .encoding_formats : list [str ] | None = None
59+ self .input_tokens : int | None = None
60+ self .dimension_count : int | None = None
61+ self .response_model_name : str | None = None
62+ self ._start (self ._get_base_attributes ())
63+
64+ def _get_base_attributes (self ) -> dict [str , Any ]:
65+ """Return sampling-relevant attributes available at span creation time."""
66+ optional_attrs = (
67+ (GenAI .GEN_AI_REQUEST_MODEL , self .request_model ),
68+ (GenAI .GEN_AI_PROVIDER_NAME , self .provider ),
69+ (server_attributes .SERVER_ADDRESS , self .server_address ),
70+ (server_attributes .SERVER_PORT , self .server_port ),
71+ )
72+ return {
73+ GenAI .GEN_AI_OPERATION_NAME : self ._operation_name ,
74+ ** {k : v for k , v in optional_attrs if v is not None },
75+ }
7176
7277 def _get_metric_attributes (self ) -> dict [str , Any ]:
7378 optional_attrs = (
0 commit comments