Skip to content

Commit 8fdae92

Browse files
committed
update attributes
1 parent 9c575fb commit 8fdae92

6 files changed

Lines changed: 42 additions & 21 deletions

File tree

veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ def load_tracer() -> None:
7070
else:
7171
exporters.append(exporter_cls())
7272

73-
tracer = OpentelemetryTracer(
74-
name="veadk_tracer", app_name=agent_run_config.app_name, exporters=exporters
75-
)
73+
tracer = OpentelemetryTracer(name="veadk_tracer", exporters=exporters)
7674
agent_run_config.agent.tracers.extend([tracer])
7775

7876

veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import json
16+
from xml.etree.ElementTree import VERSION
1617

1718
from veadk.tracing.telemetry.attributes.extractors.types import (
1819
ExtractorResponse,
@@ -359,6 +360,12 @@ def llm_gen_ai_choice(params: LLMAttributesParams) -> ExtractorResponse:
359360
return ExtractorResponse(type="event", content=message)
360361

361362

363+
def llm_openinference_instrumentation_veadk(
364+
params: LLMAttributesParams,
365+
) -> ExtractorResponse:
366+
return ExtractorResponse(content=VERSION)
367+
368+
362369
LLM_ATTRIBUTES = {
363370
"gen_ai.request.model": llm_gen_ai_request_model,
364371
"gen_ai.request.type": llm_gen_ai_request_type,
@@ -381,4 +388,5 @@ def llm_gen_ai_choice(params: LLMAttributesParams) -> ExtractorResponse:
381388
"gen_ai.user.message": llm_gen_ai_user_message,
382389
"gen_ai.assistant.message": llm_gen_ai_assistant_message,
383390
"gen_ai.choice": llm_gen_ai_choice,
391+
"openinference.instrumentation.veadk": llm_openinference_instrumentation_veadk,
384392
}

veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,27 @@ def tool_gen_ai_tool_message(params: ToolAttributesParams) -> ExtractorResponse:
3939
return ExtractorResponse(type="event", content=tool_input)
4040

4141

42-
# def tool_gen_ai_tool_message(params: ToolAttributesParams) -> ExtractorResponse:
43-
# # tool_output = {
44-
# # "id": params.function_response_event.,
45-
# # "name": ...,
46-
# # "response": ...,
47-
# # }
48-
# print(params.function_response_event)
49-
# # return ExtractorResponse(content=json.dumps(tool_output) or "<unknown_tool_output>")
42+
def tool_cozeloop_input(params: ToolAttributesParams) -> ExtractorResponse:
43+
tool_input = {
44+
"name": params.tool.name,
45+
"description": params.tool.description,
46+
"parameters": params.args,
47+
}
48+
return ExtractorResponse(content=json.dumps(tool_input) or "<unknown_tool_input>")
49+
50+
51+
def tool_cozeloop_output(params: ToolAttributesParams) -> ExtractorResponse:
52+
function_response = params.function_response_event.get_function_responses()[0]
53+
tool_output = {
54+
"id": function_response.id,
55+
"name": function_response.name,
56+
"response": function_response.response,
57+
}
58+
return ExtractorResponse(content=json.dumps(tool_output) or "<unknown_tool_output>")
5059

5160

5261
TOOL_ATTRIBUTES = {
5362
"gen_ai.operation.name": tool_gen_ai_operation_name,
54-
"gen_ai.tool.message": tool_gen_ai_tool_message,
63+
"cozeloop.input": tool_cozeloop_input, # CozeLoop required
64+
"cozeloop.output": tool_cozeloop_output, # CozeLoop required
5565
}

veadk/tracing/telemetry/exporters/apmplus_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _init_meter_uploader(self, exporter_id: str) -> MeterUploader:
8383
endpoint=self.config.endpoint, headers=self.headers
8484
)
8585
metric_reader = PeriodicExportingMetricReader(exporter)
86-
# set provider
86+
8787
metrics_api.set_meter_provider(
8888
metrics_sdk.MeterProvider(metric_readers=[metric_reader], resource=resource)
8989
)

veadk/tracing/telemetry/metrics/opentelemetry_metrics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from google.adk.models import LlmResponse
14+
15+
from google.adk.models.llm_response import LlmResponse
1516
from opentelemetry import metrics
1617
from opentelemetry.metrics._internal import Meter
1718

veadk/tracing/telemetry/telemetry.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@
3333
logger = get_logger(__name__)
3434

3535

36-
def upload_metrics(invocation_context: InvocationContext, llm_response: LlmResponse):
37-
tracers = invocation_context.agent.tracers
38-
for tracer in tracers:
39-
for exporter in getattr(tracer, "exporters", []):
40-
if getattr(exporter, "meter_uploader", None):
41-
exporter.meter_uploader.record(llm_response)
36+
def upload_metrics(
37+
invocation_context: InvocationContext, llm_response: LlmResponse
38+
) -> None:
39+
from veadk.agent import Agent
40+
41+
if isinstance(invocation_context.agent, Agent):
42+
tracers = invocation_context.agent.tracers
43+
for tracer in tracers:
44+
for exporter in getattr(tracer, "exporters", []):
45+
if getattr(exporter, "meter_uploader", None):
46+
exporter.meter_uploader.record(llm_response)
4247

4348

4449
def trace_send_data(): ...
@@ -139,5 +144,4 @@ def trace_call_llm(
139144
response: ExtractorResponse = attr_extractor(params)
140145
ExtractorResponse.update_span(span, attr_name, response)
141146

142-
# Report meter
143147
upload_metrics(invocation_context, llm_response)

0 commit comments

Comments
 (0)