File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,23 @@ def common_gen_ai_session_id(**kwargs) -> str:
115115 return session_id or "<unknown_session_id>"
116116
117117
118+ def common_gen_ai_invocation_id (** kwargs ) -> str :
119+ """Extract the invocation identifier from context.
120+
121+ Provides invocation-level identification for organizing telemetry data
122+ by individual API calls and enabling detailed analysis of each operation.
123+
124+ Args:
125+ **kwargs: Keyword arguments containing context information.
126+ Expected to include 'invocation_id' key.
127+
128+ Returns:
129+ str: Invocation identifier or placeholder if not available
130+ """
131+ invocation_id = kwargs .get ("invocation_id" )
132+ return invocation_id or "<unknown_invocation_id>"
133+
134+
118135def common_cozeloop_report_source (** kwargs ) -> str :
119136 """Extract the CozeLoop report source identifier.
120137
@@ -175,6 +192,7 @@ def llm_openinference_instrumentation_veadk(**kwargs) -> str:
175192 "app.name" : common_gen_ai_app_name , # TLS required
176193 "user.id" : common_gen_ai_user_id , # CozeLoop / TLS required
177194 "session.id" : common_gen_ai_session_id , # CozeLoop / TLS required
195+ "invocation.id" : common_gen_ai_invocation_id , # CozeLoop required
178196 "cozeloop.report.source" : common_cozeloop_report_source , # CozeLoop required
179197 "cozeloop.call_type" : common_cozeloop_call_type , # CozeLoop required
180198}
Original file line number Diff line number Diff line change @@ -147,7 +147,10 @@ def _set_agent_input_attribute(
147147 if part .text :
148148 span .add_event (
149149 "gen_ai.user.message" ,
150- {f"parts.{ idx } .type" : "text" , f"parts.{ idx } .content" : part .text },
150+ {
151+ f"parts.{ idx } .type" : "text" ,
152+ f"parts.{ idx } .content" : part .text ,
153+ },
151154 )
152155 if part .inline_data :
153156 span .add_event (
@@ -186,7 +189,8 @@ def _set_agent_output_attribute(span: Span, llm_response: LlmResponse) -> None:
186189 if content and content .parts :
187190 # set gen_ai.output attribute required by APMPlus
188191 span .set_attribute (
189- "gen_ai.output" , safe_json_serialize (content .model_dump (exclude_none = True ))
192+ "gen_ai.output" ,
193+ safe_json_serialize (content .model_dump (exclude_none = True )),
190194 )
191195
192196 for idx , part in enumerate (content .parts ):
@@ -374,6 +378,7 @@ def trace_call_llm(
374378 user_id = invocation_context .user_id ,
375379 app_name = invocation_context .app_name ,
376380 session_id = invocation_context .session .id ,
381+ invocation_id = invocation_context .invocation_id ,
377382 model_provider = invocation_context .agent .model_provider
378383 if isinstance (invocation_context .agent , Agent )
379384 else "" ,
You can’t perform that action at this time.
0 commit comments