diff --git a/python/fi_instrumentation/grpc/tracer.proto b/python/fi_instrumentation/grpc/tracer.proto deleted file mode 100644 index 5ca40776b..000000000 --- a/python/fi_instrumentation/grpc/tracer.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package tfc.tracer; - -import "google/protobuf/struct.proto"; - -service ObservationSpanController { - rpc CreateOtelSpan(CreateOtelSpanRequest) returns (CreateOtelSpanResponse) {} -} - -message CreateOtelSpanRequest { - repeated google.protobuf.Struct otel_data_list = 1; -} - -message CreateOtelSpanResponse { - repeated string ids = 1; -} - diff --git a/python/fi_instrumentation/grpc/tracer_pb2.py b/python/fi_instrumentation/grpc/tracer_pb2.py deleted file mode 100644 index aac0a7e8b..000000000 --- a/python/fi_instrumentation/grpc/tracer_pb2.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# NO CHECKED-IN PROTOBUF GENCODE -# source: tracer/grpc/tracer.proto -# Protobuf Python Version: 5.29.0 -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import runtime_version as _runtime_version -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -_runtime_version.ValidateProtobufRuntimeVersion( - _runtime_version.Domain.PUBLIC, - 5, - 29, - 0, - '', - 'tracer/grpc/tracer.proto' -) -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x18tracer/grpc/tracer.proto\x12\ntfc.tracer\x1a\x1cgoogle/protobuf/struct.proto\"H\n\x15\x43reateOtelSpanRequest\x12/\n\x0eotel_data_list\x18\x01 \x03(\x0b\x32\x17.google.protobuf.Struct\"%\n\x16\x43reateOtelSpanResponse\x12\x0b\n\x03ids\x18\x01 \x03(\t2v\n\x19ObservationSpanController\x12Y\n\x0e\x43reateOtelSpan\x12!.tfc.tracer.CreateOtelSpanRequest\x1a\".tfc.tracer.CreateOtelSpanResponse\"\x00\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'tracer.grpc.tracer_pb2', _globals) -if not _descriptor._USE_C_DESCRIPTORS: - DESCRIPTOR._loaded_options = None - _globals['_CREATEOTELSPANREQUEST']._serialized_start=70 - _globals['_CREATEOTELSPANREQUEST']._serialized_end=142 - _globals['_CREATEOTELSPANRESPONSE']._serialized_start=144 - _globals['_CREATEOTELSPANRESPONSE']._serialized_end=181 - _globals['_OBSERVATIONSPANCONTROLLER']._serialized_start=183 - _globals['_OBSERVATIONSPANCONTROLLER']._serialized_end=301 -# @@protoc_insertion_point(module_scope) diff --git a/python/fi_instrumentation/grpc/tracer_pb2_grpc.py b/python/fi_instrumentation/grpc/tracer_pb2_grpc.py deleted file mode 100644 index 7288fea8f..000000000 --- a/python/fi_instrumentation/grpc/tracer_pb2_grpc.py +++ /dev/null @@ -1,97 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc -import warnings - -from fi_instrumentation.grpc import tracer_pb2 as tracer_dot_grpc_dot_tracer__pb2 - -GRPC_GENERATED_VERSION = '1.71.0' -GRPC_VERSION = grpc.__version__ -_version_not_supported = False - -try: - from grpc._utilities import first_version_is_lower - _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION) -except ImportError: - _version_not_supported = True - -if _version_not_supported: - raise RuntimeError( - f'The grpc package installed is at version {GRPC_VERSION},' - + f' but the generated code in tracer/grpc/tracer_pb2_grpc.py depends on' - + f' grpcio>={GRPC_GENERATED_VERSION}.' - + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}' - + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.' - ) - - -class ObservationSpanControllerStub(object): - """Missing associated documentation comment in .proto file.""" - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.CreateOtelSpan = channel.unary_unary( - '/tfc.tracer.ObservationSpanController/CreateOtelSpan', - request_serializer=tracer_dot_grpc_dot_tracer__pb2.CreateOtelSpanRequest.SerializeToString, - response_deserializer=tracer_dot_grpc_dot_tracer__pb2.CreateOtelSpanResponse.FromString, - _registered_method=True) - - -class ObservationSpanControllerServicer(object): - """Missing associated documentation comment in .proto file.""" - - def CreateOtelSpan(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_ObservationSpanControllerServicer_to_server(servicer, server): - rpc_method_handlers = { - 'CreateOtelSpan': grpc.unary_unary_rpc_method_handler( - servicer.CreateOtelSpan, - request_deserializer=tracer_dot_grpc_dot_tracer__pb2.CreateOtelSpanRequest.FromString, - response_serializer=tracer_dot_grpc_dot_tracer__pb2.CreateOtelSpanResponse.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'tfc.tracer.ObservationSpanController', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - server.add_registered_method_handlers('tfc.tracer.ObservationSpanController', rpc_method_handlers) - - - # This class is part of an EXPERIMENTAL API. -class ObservationSpanController(object): - """Missing associated documentation comment in .proto file.""" - - @staticmethod - def CreateOtelSpan(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary( - request, - target, - '/tfc.tracer.ObservationSpanController/CreateOtelSpan', - tracer_dot_grpc_dot_tracer__pb2.CreateOtelSpanRequest.SerializeToString, - tracer_dot_grpc_dot_tracer__pb2.CreateOtelSpanResponse.FromString, - options, - channel_credentials, - insecure, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - _registered_method=True) diff --git a/python/fi_instrumentation/otel.py b/python/fi_instrumentation/otel.py index 8add9fa13..067d044fb 100644 --- a/python/fi_instrumentation/otel.py +++ b/python/fi_instrumentation/otel.py @@ -5,16 +5,13 @@ import os import signal import sys -import time import uuid -import warnings from enum import Enum -from typing import Any, Dict, List, Optional, Tuple, Type, Union, cast +from typing import Any, Dict, List, Optional, Tuple, Type, Union from urllib.parse import ParseResult, urlparse import requests from fi_instrumentation.fi_types import ( - Endpoints, EvalName, EvalTag, ProjectType, @@ -46,9 +43,6 @@ from opentelemetry.sdk.trace.export import BatchSpanProcessor as _BatchSpanProcessor from opentelemetry.sdk.trace.export import SimpleSpanProcessor as _SimpleSpanProcessor from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult -import grpc -from google.protobuf.struct_pb2 import Struct -from fi_instrumentation.grpc import tracer_pb2, tracer_pb2_grpc PROJECT_NAME = "project_name" PROJECT_TYPE = "project_type" @@ -505,106 +499,6 @@ def __init__(self, *args: Any, **kwargs: Any): bound_args.arguments["endpoint"] = endpoint super().__init__(*bound_args.args, **bound_args.kwargs) - def _convert_attributes(self, attributes): - """Convert mappingproxy objects to regular dictionaries.""" - if attributes is None: - return {} - if not isinstance(attributes, dict): - return dict(attributes) - return attributes - - def _format_trace_id(self, trace_id: int) -> str: - # Format the trace_id as a 32-character hexadecimal UUID - return f"{trace_id:032x}" - - def _format_span_id(self, span_id: int) -> str: - # Format the span_id as a 16-character hexadecimal - return f"{span_id:016x}" - - def export(self, spans) -> SpanExportResult: - """ - Exports a batch of spans in JSON format. - Args: - spans (list): A list of spans to export. - Returns: - SpanExportResult: Indicates the success or failure of the export. - """ - if not self._endpoint: - warnings.warn("gRPC Exporter endpoint is not configured. Cannot export spans.") - return SpanExportResult.FAILURE - - spans_data = [] - for span in spans: - span_data = { - "trace_id": self._format_trace_id(span.context.trace_id), - "span_id": self._format_span_id(span.context.span_id), - "name": span.name, - "start_time": span.start_time, - "end_time": span.end_time, - "attributes": self._convert_attributes(span.attributes), - "events": [ - { - "name": event.name, - "attributes": self._convert_attributes(event.attributes), - "timestamp": event.timestamp, - } - for event in span.events - ], - "status": span.status.status_code.name, - "parent_id": ( - self._format_span_id(span.parent.span_id) - if span.parent - else None - ), - "project_name": span.resource.attributes.get(PROJECT_NAME), - "project_type": span.resource.attributes.get(PROJECT_TYPE), - "project_version_name": span.resource.attributes.get( - PROJECT_VERSION_NAME - ), - "project_version_id": span.resource.attributes.get( - PROJECT_VERSION_ID - ), - "latency": math.floor( - (span.end_time - span.start_time) / 1000000 - ), - "eval_tags": span.resource.attributes.get(EVAL_TAGS), - "metadata": span.resource.attributes.get(METADATA), - "session_name": span.resource.attributes.get(SESSION_NAME), - } - spans_data.append(span_data) - - if not spans_data: - return SpanExportResult.SUCCESS - - try: - - with grpc.insecure_channel(self._endpoint) as channel: - stub = tracer_pb2_grpc.ObservationSpanControllerStub(channel) - metadata = list(self._headers) if self._headers else None - - otel_data_list = [] - for span_data_item in spans_data: - s = Struct() - s.update(span_data_item) - otel_data_list.append(s) - - request = tracer_pb2.CreateOtelSpanRequest( - otel_data_list=otel_data_list - ) - - try: - stub.CreateOtelSpan(request, metadata=metadata) - except grpc.RpcError as e: - print(f"Failed to export spans via gRPC: {e.details()}") - - return SpanExportResult.SUCCESS - - except Exception as e: - import traceback - print(traceback.format_exc()) - print(f"Failed to export spans due to an unexpected error: {e}") - return SpanExportResult.FAILURE - def shutdown(self) -> None: """Clean up any resources before shutting down.""" try: diff --git a/python/frameworks/anthropic/examples/guardrail_example.py b/python/frameworks/anthropic/examples/guardrail_example.py index 0cb6936b0..20effda6a 100644 --- a/python/frameworks/anthropic/examples/guardrail_example.py +++ b/python/frameworks/anthropic/examples/guardrail_example.py @@ -9,8 +9,6 @@ from fi.evals import Evaluator, Protect from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType -from fi_instrumentation.instrumentation.config import TraceConfig -from opentelemetry import trace from traceai_anthropic import AnthropicInstrumentor # Initialize tracer diff --git a/python/frameworks/anthropic/traceai_anthropic/__init__.py b/python/frameworks/anthropic/traceai_anthropic/__init__.py index a55bb2bc9..9649c80b8 100644 --- a/python/frameworks/anthropic/traceai_anthropic/__init__.py +++ b/python/frameworks/anthropic/traceai_anthropic/__init__.py @@ -47,7 +47,6 @@ def _instrument(self, **kwargs: Any) -> None: except ImportError: logger.warning("ai-evaluation is not installed, please install it to trace protect") Protect = None - pass if not (tracer_provider := kwargs.get("tracer_provider")): tracer_provider = trace_api.get_tracer_provider() @@ -110,7 +109,6 @@ def _uninstrument(self, **kwargs: Any) -> None: except ImportError: logger.warning("ai-evaluation is not installed, please install it to trace protect") Protect = None - pass if self._original_completions_create is not None: Completions.create = self._original_completions_create # type: ignore[method-assign] diff --git a/python/frameworks/dspy/examples/embedding.py b/python/frameworks/dspy/examples/embedding.py index c983c7432..787da4788 100644 --- a/python/frameworks/dspy/examples/embedding.py +++ b/python/frameworks/dspy/examples/embedding.py @@ -1,10 +1,6 @@ import dspy from fi_instrumentation import register from fi_instrumentation.fi_types import ( - EvalName, - EvalSpanKind, - EvalTag, - EvalTagType, ProjectType, ) from traceai_dspy import DSPyInstrumentor diff --git a/python/frameworks/google-adk/examples/testing_google_adk.py b/python/frameworks/google-adk/examples/testing_google_adk.py index 07b27dde6..e6c87c668 100644 --- a/python/frameworks/google-adk/examples/testing_google_adk.py +++ b/python/frameworks/google-adk/examples/testing_google_adk.py @@ -5,9 +5,6 @@ from google.genai import types from traceai_google_adk import GoogleADKInstrumentor -from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter -from opentelemetry.sdk import trace as trace_sdk -from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType diff --git a/python/frameworks/guardrails/traceai_guardrails/guardrails_example.py b/python/frameworks/guardrails/traceai_guardrails/guardrails_example.py index ee478819a..effa598e8 100644 --- a/python/frameworks/guardrails/traceai_guardrails/guardrails_example.py +++ b/python/frameworks/guardrails/traceai_guardrails/guardrails_example.py @@ -1,4 +1,3 @@ -import os from dotenv import load_dotenv from fi_instrumentation import register diff --git a/python/frameworks/langchain/examples/exchange_rate_tool.py b/python/frameworks/langchain/examples/exchange_rate_tool.py index ef2095599..ed94cafa4 100644 --- a/python/frameworks/langchain/examples/exchange_rate_tool.py +++ b/python/frameworks/langchain/examples/exchange_rate_tool.py @@ -1,5 +1,3 @@ -from datetime import date -from typing import Optional import requests from fi_instrumentation import register @@ -8,7 +6,6 @@ EvalSpanKind, EvalTag, EvalTagType, - ProjectType, ) from langchain import agents from langchain.tools import tool diff --git a/python/frameworks/langchain/examples/language_agent_tree_search.py b/python/frameworks/langchain/examples/language_agent_tree_search.py index 6012dbbd8..ffe585a23 100644 --- a/python/frameworks/langchain/examples/language_agent_tree_search.py +++ b/python/frameworks/langchain/examples/language_agent_tree_search.py @@ -1,12 +1,12 @@ import math -from collections import defaultdict, deque -from typing import Literal, Optional +from collections import deque +from typing import Optional from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType from langchain_community.tools.tavily_search import TavilySearchResults from langchain_community.utilities.tavily_search import TavilySearchAPIWrapper -from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, ToolMessage +from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.output_parsers.openai_tools import ( JsonOutputToolsParser, PydanticToolsParser, diff --git a/python/frameworks/langchain/examples/multimodal.py b/python/frameworks/langchain/examples/multimodal.py index 257e3aa83..f4aa3cf35 100644 --- a/python/frameworks/langchain/examples/multimodal.py +++ b/python/frameworks/langchain/examples/multimodal.py @@ -1,5 +1,4 @@ import base64 -from io import BytesIO import httpx from fi_instrumentation import register @@ -13,7 +12,6 @@ from langchain.chains import LLMChain from langchain.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI -from PIL import Image from traceai_langchain import LangChainInstrumentor # Configure trace provider with custom evaluation tags diff --git a/python/frameworks/langchain/examples/rerank.py b/python/frameworks/langchain/examples/rerank.py index 1f9dea376..5f33d348d 100644 --- a/python/frameworks/langchain/examples/rerank.py +++ b/python/frameworks/langchain/examples/rerank.py @@ -1,4 +1,3 @@ -import os from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType @@ -6,7 +5,6 @@ from langchain.retrievers import ContextualCompressionRetriever from langchain.retrievers.document_compressors import CohereRerank from langchain.schema import Document -from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import FAISS from traceai_langchain import LangChainInstrumentor diff --git a/python/frameworks/langchain/examples/sqlagent.py b/python/frameworks/langchain/examples/sqlagent.py index 7e489dd02..ae5f29fd8 100644 --- a/python/frameworks/langchain/examples/sqlagent.py +++ b/python/frameworks/langchain/examples/sqlagent.py @@ -1,4 +1,4 @@ -from typing import Annotated, Literal +from typing import Annotated from fi_instrumentation import register from fi_instrumentation.fi_types import ( @@ -18,7 +18,6 @@ from langgraph.graph import END, START, StateGraph from langgraph.graph.message import AnyMessage, add_messages from langgraph.prebuilt import ToolNode -from pydantic import BaseModel, Field from traceai_langchain import LangChainInstrumentor from typing_extensions import TypedDict diff --git a/python/frameworks/langchain/examples/tool_calling_agent.py b/python/frameworks/langchain/examples/tool_calling_agent.py index 66e1aca74..a8a81febd 100644 --- a/python/frameworks/langchain/examples/tool_calling_agent.py +++ b/python/frameworks/langchain/examples/tool_calling_agent.py @@ -1,6 +1,5 @@ import os -import opentelemetry.trace as trace_api import requests from fi.evals import Evaluator, Protect from fi_instrumentation import register diff --git a/python/frameworks/langchain/traceai_langchain/__init__.py b/python/frameworks/langchain/traceai_langchain/__init__.py index eaa60e4a7..b1a37dd49 100644 --- a/python/frameworks/langchain/traceai_langchain/__init__.py +++ b/python/frameworks/langchain/traceai_langchain/__init__.py @@ -3,7 +3,7 @@ from uuid import UUID import langchain_core -from fi_instrumentation import FITracer, TraceConfig +from fi_instrumentation import TraceConfig from fi_instrumentation.instrumentation._protect_wrapper import GuardrailProtectWrapper from langchain_core.callbacks import BaseCallbackManager from langchain_core.runnables.config import var_child_runnable_config # noqa F401 @@ -42,7 +42,6 @@ def _instrument(self, **kwargs: Any) -> None: except ImportError: logger.warning("ai-evaluation is not installed, please install it to trace protect") Protect = None - pass from fi_instrumentation.instrumentation._tracers import FITracer from traceai_langchain._tracer import FiTracer as LangChainFiTracer diff --git a/python/frameworks/litellm/examples/rerank.py b/python/frameworks/litellm/examples/rerank.py index 243be7d67..c11427316 100644 --- a/python/frameworks/litellm/examples/rerank.py +++ b/python/frameworks/litellm/examples/rerank.py @@ -1,9 +1,5 @@ from fi_instrumentation import register from fi_instrumentation.fi_types import ( - EvalName, - EvalSpanKind, - EvalTag, - EvalTagType, ProjectType, ) from litellm import rerank diff --git a/python/frameworks/llama_index/examples/rerank.py b/python/frameworks/llama_index/examples/rerank.py index 7dd456608..8dd18aec5 100644 --- a/python/frameworks/llama_index/examples/rerank.py +++ b/python/frameworks/llama_index/examples/rerank.py @@ -3,10 +3,6 @@ import requests from fi_instrumentation import register from fi_instrumentation.fi_types import ( - EvalName, - EvalSpanKind, - EvalTag, - EvalTagType, ProjectType, ) from llama_index.core import Document, VectorStoreIndex diff --git a/python/frameworks/llama_index/traceai_llamaindex/_handler.py b/python/frameworks/llama_index/traceai_llamaindex/_handler.py index e2c3b4524..fd9718817 100644 --- a/python/frameworks/llama_index/traceai_llamaindex/_handler.py +++ b/python/frameworks/llama_index/traceai_llamaindex/_handler.py @@ -260,7 +260,6 @@ def process_output(self, instance: Any, result: Any) -> None: self[RAW_OUTPUT] = result.model_dump_json(exclude_unset=True) except BaseException as e: logger.exception(str(e)) - pass else: try: self[OUTPUT_VALUE] = safe_json_dumps(result) @@ -269,7 +268,6 @@ def process_output(self, instance: Any, result: Any) -> None: self[RAW_OUTPUT] = safe_json_dumps(result) except BaseException as e: logger.exception(str(e)) - pass @singledispatchmethod def process_instance(self, instance: Any) -> None: ... @@ -896,7 +894,6 @@ def handle(self, event: BaseEvent, **kwargs: Any) -> Any: logger.exception( f"Error processing event of type {event.__class__.__qualname__}" ) - pass return event diff --git a/python/frameworks/openai/examples/audio_chat.py b/python/frameworks/openai/examples/audio_chat.py index 885bb7f2d..a956f5737 100644 --- a/python/frameworks/openai/examples/audio_chat.py +++ b/python/frameworks/openai/examples/audio_chat.py @@ -1,9 +1,5 @@ from fi_instrumentation import register from fi_instrumentation.fi_types import ( - EvalName, - EvalSpanKind, - EvalTag, - EvalTagType, ProjectType, ) from traceai_openai import OpenAIInstrumentor diff --git a/python/frameworks/openai/examples/chat_completions.py b/python/frameworks/openai/examples/chat_completions.py index 4321efccc..88061903f 100644 --- a/python/frameworks/openai/examples/chat_completions.py +++ b/python/frameworks/openai/examples/chat_completions.py @@ -1,6 +1,4 @@ import openai -import sys -import os # Now import from local paths from fi_instrumentation.otel import register @@ -11,7 +9,6 @@ EvalTag, EvalTagType, ProjectType, - ModelChoices, ) from traceai_openai import OpenAIInstrumentor diff --git a/python/frameworks/portkey/pyproject.toml b/python/frameworks/portkey/pyproject.toml index ef20d8ef5..97b50a599 100644 --- a/python/frameworks/portkey/pyproject.toml +++ b/python/frameworks/portkey/pyproject.toml @@ -12,7 +12,7 @@ packages = [ [tool.poetry.dependencies] python = ">3.9, <3.13" portkey-ai = ">0.1.0" -fi-instrumentation-otel = "0.1.7" +fi-instrumentation-otel = "^0.1.8" [build-system] diff --git a/python/frameworks/vertexai/examples/embedding.py b/python/frameworks/vertexai/examples/embedding.py index 82ce1f6b8..f30163d4a 100644 --- a/python/frameworks/vertexai/examples/embedding.py +++ b/python/frameworks/vertexai/examples/embedding.py @@ -1,16 +1,9 @@ -import os -import vertexai from fi_instrumentation import register from fi_instrumentation.fi_types import ( - EvalName, - EvalSpanKind, - EvalTag, - EvalTagType, ProjectType, ) from traceai_vertexai import VertexAIInstrumentor -from vertexai.generative_models import GenerativeModel, Part from vertexai.language_models import TextEmbeddingInput from vertexai.preview.language_models import TextEmbeddingModel diff --git a/python/frameworks/vertexai/examples/tool_calling.py b/python/frameworks/vertexai/examples/tool_calling.py index c215dde2b..e76fecdf9 100644 --- a/python/frameworks/vertexai/examples/tool_calling.py +++ b/python/frameworks/vertexai/examples/tool_calling.py @@ -3,10 +3,6 @@ import vertexai from fi_instrumentation import register from fi_instrumentation.fi_types import ( - EvalName, - EvalSpanKind, - EvalTag, - EvalTagType, ProjectType, ) from traceai_vertexai import VertexAIInstrumentor diff --git a/python/pyproject.toml b/python/pyproject.toml index 3506bc51d..aa0ff41c8 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fi-instrumentation-otel" -version = "0.1.8" +version = "0.1.9" description = "OpenTelemetry instrumentation" authors = ["Future AGI "] readme = "README.md" diff --git a/typescript/packages/fi-core/package.json b/typescript/packages/fi-core/package.json index 7744effde..6df773c2b 100644 --- a/typescript/packages/fi-core/package.json +++ b/typescript/packages/fi-core/package.json @@ -1,6 +1,6 @@ { "name": "@traceai/fi-core", - "version": "0.1.12", + "version": "0.1.14", "description": "Core OpenTelemetry instrumentation for TypeScript", "main": "./dist/src/index.js", "module": "./dist/esm/index.js", @@ -15,8 +15,7 @@ }, "scripts": { "prebuild": "rimraf dist", - "build": "pnpm run build:proto && tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json && pnpm run postbuild", - "build:proto": "npx protoc --ts_out src/generated --proto_path src/grpc src/grpc/tracer.proto", + "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json && pnpm run postbuild", "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json", "test": "jest", "lint": "eslint . --ext .ts", @@ -50,7 +49,7 @@ "@protobuf-ts/grpc-transport": "^2.11.0", "@protobuf-ts/runtime": "^2.11.0", "@protobuf-ts/runtime-rpc": "^2.11.0", - "@traceai/fi-semantic-conventions": "^0.1.8", + "@traceai/fi-semantic-conventions": "^0.1.9", "uuid": "^11.1.0" }, "devDependencies": { diff --git a/typescript/packages/fi-core/src/fi_types.ts b/typescript/packages/fi-core/src/fi_types.ts index 22bc85036..e33787357 100644 --- a/typescript/packages/fi-core/src/fi_types.ts +++ b/typescript/packages/fi-core/src/fi_types.ts @@ -885,7 +885,7 @@ class EvalTag implements IEvalTag { metadata?: Record | null; model?: ModelChoices; - private constructor(params: { + constructor(params: { type: EvalTagType; value: EvalSpanKind; eval_name: EvalName | string; @@ -949,15 +949,13 @@ class EvalTag implements IEvalTag { if (!customEvalTemplate.result?.isUserEvalTemplate) { if (!Object.values(EvalName).includes(this.eval_name as EvalName)) { throw new Error( - `eval_name must be a valid EvalName enum if its not a custom eval template, got ${ - this.eval_name - }. Expected values are: ${Object.values(EvalName).join(", ")}` + `Invalid eval_name '${this.eval_name}'. Expected one of: ${Object.values(EvalName).slice(0, 5).join(', ')}... (${Object.values(EvalName).length} total options)` ); } if (!this.model || !Object.values(ModelChoices).includes(this.model)) { throw new Error( - `Model must be provied in case of fagi evals. Model must be a valid model name, got ${ + `Model must be provided in case of fagi evals. Model must be a valid model name, got ${ this.model }. Expected values are: ${Object.values(ModelChoices).join(", ")}` ); diff --git a/typescript/packages/fi-core/src/generated/google/protobuf/struct.ts b/typescript/packages/fi-core/src/generated/google/protobuf/struct.ts deleted file mode 100644 index e66e98730..000000000 --- a/typescript/packages/fi-core/src/generated/google/protobuf/struct.ts +++ /dev/null @@ -1,484 +0,0 @@ -// @generated by protobuf-ts 2.11.0 -// @generated from protobuf file "google/protobuf/struct.proto" (package "google.protobuf", syntax proto3) -// tslint:disable -// -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; -import type { IBinaryWriter } from "@protobuf-ts/runtime"; -import { WireType } from "@protobuf-ts/runtime"; -import type { BinaryReadOptions } from "@protobuf-ts/runtime"; -import type { IBinaryReader } from "@protobuf-ts/runtime"; -import { UnknownFieldHandler } from "@protobuf-ts/runtime"; -import type { PartialMessage } from "@protobuf-ts/runtime"; -import { reflectionMergePartial } from "@protobuf-ts/runtime"; -import { isJsonObject } from "@protobuf-ts/runtime"; -import { typeofJsonValue } from "@protobuf-ts/runtime"; -import type { JsonValue } from "@protobuf-ts/runtime"; -import type { JsonReadOptions } from "@protobuf-ts/runtime"; -import type { JsonWriteOptions } from "@protobuf-ts/runtime"; -import type { JsonObject } from "@protobuf-ts/runtime"; -import { MessageType } from "@protobuf-ts/runtime"; -/** - * `Struct` represents a structured data value, consisting of fields - * which map to dynamically typed values. In some languages, `Struct` - * might be supported by a native representation. For example, in - * scripting languages like JS a struct is represented as an - * object. The details of that representation are described together - * with the proto support for the language. - * - * The JSON representation for `Struct` is JSON object. - * - * @generated from protobuf message google.protobuf.Struct - */ -export interface Struct { - /** - * Unordered map of dynamically typed values. - * - * @generated from protobuf field: map fields = 1 - */ - fields: { - [key: string]: Value; - }; -} -/** - * `Value` represents a dynamically typed value which can be either - * null, a number, a string, a boolean, a recursive struct value, or a - * list of values. A producer of value is expected to set one of these - * variants. Absence of any variant indicates an error. - * - * The JSON representation for `Value` is JSON value. - * - * @generated from protobuf message google.protobuf.Value - */ -export interface Value { - /** - * The kind of value. - * - * @generated from protobuf oneof: kind - */ - kind: { - oneofKind: "nullValue"; - /** - * Represents a null value. - * - * @generated from protobuf field: google.protobuf.NullValue null_value = 1 - */ - nullValue: NullValue; - } | { - oneofKind: "numberValue"; - /** - * Represents a double value. - * - * @generated from protobuf field: double number_value = 2 - */ - numberValue: number; - } | { - oneofKind: "stringValue"; - /** - * Represents a string value. - * - * @generated from protobuf field: string string_value = 3 - */ - stringValue: string; - } | { - oneofKind: "boolValue"; - /** - * Represents a boolean value. - * - * @generated from protobuf field: bool bool_value = 4 - */ - boolValue: boolean; - } | { - oneofKind: "structValue"; - /** - * Represents a structured value. - * - * @generated from protobuf field: google.protobuf.Struct struct_value = 5 - */ - structValue: Struct; - } | { - oneofKind: "listValue"; - /** - * Represents a repeated `Value`. - * - * @generated from protobuf field: google.protobuf.ListValue list_value = 6 - */ - listValue: ListValue; - } | { - oneofKind: undefined; - }; -} -/** - * `ListValue` is a wrapper around a repeated field of values. - * - * The JSON representation for `ListValue` is JSON array. - * - * @generated from protobuf message google.protobuf.ListValue - */ -export interface ListValue { - /** - * Repeated field of dynamically typed values. - * - * @generated from protobuf field: repeated google.protobuf.Value values = 1 - */ - values: Value[]; -} -/** - * `NullValue` is a singleton enumeration to represent the null value for the - * `Value` type union. - * - * The JSON representation for `NullValue` is JSON `null`. - * - * @generated from protobuf enum google.protobuf.NullValue - */ -export enum NullValue { - /** - * Null value. - * - * @generated from protobuf enum value: NULL_VALUE = 0; - */ - NULL_VALUE = 0 -} -// @generated message type with reflection information, may provide speed optimized methods -class Struct$Type extends MessageType { - constructor() { - super("google.protobuf.Struct", [ - { no: 1, name: "fields", kind: "map", K: 9 /*ScalarType.STRING*/, V: { kind: "message", T: () => Value } } - ]); - } - /** - * Encode `Struct` to JSON object. - */ - internalJsonWrite(message: Struct, options: JsonWriteOptions): JsonValue { - let json: JsonObject = {}; - for (let [k, v] of Object.entries(message.fields)) { - json[k] = Value.toJson(v); - } - return json; - } - /** - * Decode `Struct` from JSON object. - */ - internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Struct): Struct { - if (!isJsonObject(json)) - throw new globalThis.Error("Unable to parse message " + this.typeName + " from JSON " + typeofJsonValue(json) + "."); - if (!target) - target = this.create(); - for (let [k, v] of globalThis.Object.entries(json)) { - target.fields[k] = Value.fromJson(v); - } - return target; - } - create(value?: PartialMessage): Struct { - const message = globalThis.Object.create((this.messagePrototype!)); - message.fields = {}; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Struct): Struct { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* map fields */ 1: - this.binaryReadMap1(message.fields, reader, options); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - private binaryReadMap1(map: Struct["fields"], reader: IBinaryReader, options: BinaryReadOptions): void { - let len = reader.uint32(), end = reader.pos + len, key: keyof Struct["fields"] | undefined, val: Struct["fields"][any] | undefined; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case 1: - key = reader.string(); - break; - case 2: - val = Value.internalBinaryRead(reader, reader.uint32(), options); - break; - default: throw new globalThis.Error("unknown map entry field for google.protobuf.Struct.fields"); - } - } - map[key ?? ""] = val ?? Value.create(); - } - internalBinaryWrite(message: Struct, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* map fields = 1; */ - for (let k of globalThis.Object.keys(message.fields)) { - writer.tag(1, WireType.LengthDelimited).fork().tag(1, WireType.LengthDelimited).string(k); - writer.tag(2, WireType.LengthDelimited).fork(); - Value.internalBinaryWrite(message.fields[k], writer, options); - writer.join().join(); - } - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message google.protobuf.Struct - */ -export const Struct = new Struct$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class Value$Type extends MessageType { - constructor() { - super("google.protobuf.Value", [ - { no: 1, name: "null_value", kind: "enum", oneof: "kind", T: () => ["google.protobuf.NullValue", NullValue] }, - { no: 2, name: "number_value", kind: "scalar", oneof: "kind", T: 1 /*ScalarType.DOUBLE*/ }, - { no: 3, name: "string_value", kind: "scalar", oneof: "kind", T: 9 /*ScalarType.STRING*/ }, - { no: 4, name: "bool_value", kind: "scalar", oneof: "kind", T: 8 /*ScalarType.BOOL*/ }, - { no: 5, name: "struct_value", kind: "message", oneof: "kind", T: () => Struct }, - { no: 6, name: "list_value", kind: "message", oneof: "kind", T: () => ListValue } - ]); - } - /** - * Encode `Value` to JSON value. - */ - internalJsonWrite(message: Value, options: JsonWriteOptions): JsonValue { - if (message.kind.oneofKind === undefined) - throw new globalThis.Error(); - switch (message.kind.oneofKind) { - case undefined: throw new globalThis.Error(); - case "boolValue": return message.kind.boolValue; - case "nullValue": return null; - case "numberValue": - let numberValue = message.kind.numberValue; - if (typeof numberValue == "number" && !Number.isFinite(numberValue)) - throw new globalThis.Error(); - return numberValue; - case "stringValue": return message.kind.stringValue; - case "listValue": - let listValueField = this.fields.find(f => f.no === 6); - if (listValueField?.kind !== "message") - throw new globalThis.Error(); - return listValueField.T().toJson(message.kind.listValue); - case "structValue": - let structValueField = this.fields.find(f => f.no === 5); - if (structValueField?.kind !== "message") - throw new globalThis.Error(); - return structValueField.T().toJson(message.kind.structValue); - } - } - /** - * Decode `Value` from JSON value. - */ - internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Value): Value { - if (!target) - target = this.create(); - switch (typeof json) { - case "number": - target.kind = { oneofKind: "numberValue", numberValue: json }; - break; - case "string": - target.kind = { oneofKind: "stringValue", stringValue: json }; - break; - case "boolean": - target.kind = { oneofKind: "boolValue", boolValue: json }; - break; - case "object": - if (json === null) { - target.kind = { oneofKind: "nullValue", nullValue: NullValue.NULL_VALUE }; - } - else if (globalThis.Array.isArray(json)) { - target.kind = { oneofKind: "listValue", listValue: ListValue.fromJson(json) }; - } - else { - target.kind = { oneofKind: "structValue", structValue: Struct.fromJson(json) }; - } - break; - default: throw new globalThis.Error("Unable to parse " + this.typeName + " from JSON " + typeofJsonValue(json)); - } - return target; - } - create(value?: PartialMessage): Value { - const message = globalThis.Object.create((this.messagePrototype!)); - message.kind = { oneofKind: undefined }; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Value): Value { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* google.protobuf.NullValue null_value */ 1: - message.kind = { - oneofKind: "nullValue", - nullValue: reader.int32() - }; - break; - case /* double number_value */ 2: - message.kind = { - oneofKind: "numberValue", - numberValue: reader.double() - }; - break; - case /* string string_value */ 3: - message.kind = { - oneofKind: "stringValue", - stringValue: reader.string() - }; - break; - case /* bool bool_value */ 4: - message.kind = { - oneofKind: "boolValue", - boolValue: reader.bool() - }; - break; - case /* google.protobuf.Struct struct_value */ 5: - message.kind = { - oneofKind: "structValue", - structValue: Struct.internalBinaryRead(reader, reader.uint32(), options, (message.kind as any).structValue) - }; - break; - case /* google.protobuf.ListValue list_value */ 6: - message.kind = { - oneofKind: "listValue", - listValue: ListValue.internalBinaryRead(reader, reader.uint32(), options, (message.kind as any).listValue) - }; - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: Value, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* google.protobuf.NullValue null_value = 1; */ - if (message.kind.oneofKind === "nullValue") - writer.tag(1, WireType.Varint).int32(message.kind.nullValue); - /* double number_value = 2; */ - if (message.kind.oneofKind === "numberValue") - writer.tag(2, WireType.Bit64).double(message.kind.numberValue); - /* string string_value = 3; */ - if (message.kind.oneofKind === "stringValue") - writer.tag(3, WireType.LengthDelimited).string(message.kind.stringValue); - /* bool bool_value = 4; */ - if (message.kind.oneofKind === "boolValue") - writer.tag(4, WireType.Varint).bool(message.kind.boolValue); - /* google.protobuf.Struct struct_value = 5; */ - if (message.kind.oneofKind === "structValue") - Struct.internalBinaryWrite(message.kind.structValue, writer.tag(5, WireType.LengthDelimited).fork(), options).join(); - /* google.protobuf.ListValue list_value = 6; */ - if (message.kind.oneofKind === "listValue") - ListValue.internalBinaryWrite(message.kind.listValue, writer.tag(6, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message google.protobuf.Value - */ -export const Value = new Value$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class ListValue$Type extends MessageType { - constructor() { - super("google.protobuf.ListValue", [ - { no: 1, name: "values", kind: "message", repeat: 2 /*RepeatType.UNPACKED*/, T: () => Value } - ]); - } - /** - * Encode `ListValue` to JSON array. - */ - internalJsonWrite(message: ListValue, options: JsonWriteOptions): JsonValue { - return message.values.map(v => Value.toJson(v)); - } - /** - * Decode `ListValue` from JSON array. - */ - internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: ListValue): ListValue { - if (!globalThis.Array.isArray(json)) - throw new globalThis.Error("Unable to parse " + this.typeName + " from JSON " + typeofJsonValue(json)); - if (!target) - target = this.create(); - let values = json.map(v => Value.fromJson(v)); - target.values.push(...values); - return target; - } - create(value?: PartialMessage): ListValue { - const message = globalThis.Object.create((this.messagePrototype!)); - message.values = []; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ListValue): ListValue { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* repeated google.protobuf.Value values */ 1: - message.values.push(Value.internalBinaryRead(reader, reader.uint32(), options)); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: ListValue, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* repeated google.protobuf.Value values = 1; */ - for (let i = 0; i < message.values.length; i++) - Value.internalBinaryWrite(message.values[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message google.protobuf.ListValue - */ -export const ListValue = new ListValue$Type(); diff --git a/typescript/packages/fi-core/src/generated/index.ts b/typescript/packages/fi-core/src/generated/index.ts deleted file mode 100644 index b33061c87..000000000 --- a/typescript/packages/fi-core/src/generated/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// Generated protobuf exports -export * from './tracer'; -export * from './tracer.client'; \ No newline at end of file diff --git a/typescript/packages/fi-core/src/generated/tracer.client.ts b/typescript/packages/fi-core/src/generated/tracer.client.ts deleted file mode 100644 index 8d5a44d52..000000000 --- a/typescript/packages/fi-core/src/generated/tracer.client.ts +++ /dev/null @@ -1,37 +0,0 @@ -// @generated by protobuf-ts 2.11.0 -// @generated from protobuf file "tracer.proto" (package "tfc.tracer", syntax proto3) -// tslint:disable -import type { RpcTransport } from "@protobuf-ts/runtime-rpc"; -import type { ServiceInfo } from "@protobuf-ts/runtime-rpc"; -import { ObservationSpanController } from "./tracer"; -import { stackIntercept } from "@protobuf-ts/runtime-rpc"; -import type { CreateOtelSpanResponse } from "./tracer"; -import type { CreateOtelSpanRequest } from "./tracer"; -import type { UnaryCall } from "@protobuf-ts/runtime-rpc"; -import type { RpcOptions } from "@protobuf-ts/runtime-rpc"; -/** - * @generated from protobuf service tfc.tracer.ObservationSpanController - */ -export interface IObservationSpanControllerClient { - /** - * @generated from protobuf rpc: CreateOtelSpan - */ - createOtelSpan(input: CreateOtelSpanRequest, options?: RpcOptions): UnaryCall; -} -/** - * @generated from protobuf service tfc.tracer.ObservationSpanController - */ -export class ObservationSpanControllerClient implements IObservationSpanControllerClient, ServiceInfo { - typeName = ObservationSpanController.typeName; - methods = ObservationSpanController.methods; - options = ObservationSpanController.options; - constructor(private readonly _transport: RpcTransport) { - } - /** - * @generated from protobuf rpc: CreateOtelSpan - */ - createOtelSpan(input: CreateOtelSpanRequest, options?: RpcOptions): UnaryCall { - const method = this.methods[0], opt = this._transport.mergeOptions(options); - return stackIntercept("unary", this._transport, method, opt, input); - } -} diff --git a/typescript/packages/fi-core/src/generated/tracer.ts b/typescript/packages/fi-core/src/generated/tracer.ts deleted file mode 100644 index 36e471422..000000000 --- a/typescript/packages/fi-core/src/generated/tracer.ts +++ /dev/null @@ -1,132 +0,0 @@ -// @generated by protobuf-ts 2.11.0 -// @generated from protobuf file "tracer.proto" (package "tfc.tracer", syntax proto3) -// tslint:disable -import { ServiceType } from "@protobuf-ts/runtime-rpc"; -import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; -import type { IBinaryWriter } from "@protobuf-ts/runtime"; -import { WireType } from "@protobuf-ts/runtime"; -import type { BinaryReadOptions } from "@protobuf-ts/runtime"; -import type { IBinaryReader } from "@protobuf-ts/runtime"; -import { UnknownFieldHandler } from "@protobuf-ts/runtime"; -import type { PartialMessage } from "@protobuf-ts/runtime"; -import { reflectionMergePartial } from "@protobuf-ts/runtime"; -import { MessageType } from "@protobuf-ts/runtime"; -import { Struct } from "./google/protobuf/struct"; -/** - * @generated from protobuf message tfc.tracer.CreateOtelSpanRequest - */ -export interface CreateOtelSpanRequest { - /** - * @generated from protobuf field: repeated google.protobuf.Struct otel_data_list = 1 - */ - otelDataList: Struct[]; -} -/** - * @generated from protobuf message tfc.tracer.CreateOtelSpanResponse - */ -export interface CreateOtelSpanResponse { - /** - * @generated from protobuf field: repeated string ids = 1 - */ - ids: string[]; -} -// @generated message type with reflection information, may provide speed optimized methods -class CreateOtelSpanRequest$Type extends MessageType { - constructor() { - super("tfc.tracer.CreateOtelSpanRequest", [ - { no: 1, name: "otel_data_list", kind: "message", repeat: 2 /*RepeatType.UNPACKED*/, T: () => Struct } - ]); - } - create(value?: PartialMessage): CreateOtelSpanRequest { - const message = globalThis.Object.create((this.messagePrototype!)); - message.otelDataList = []; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: CreateOtelSpanRequest): CreateOtelSpanRequest { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* repeated google.protobuf.Struct otel_data_list */ 1: - message.otelDataList.push(Struct.internalBinaryRead(reader, reader.uint32(), options)); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: CreateOtelSpanRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* repeated google.protobuf.Struct otel_data_list = 1; */ - for (let i = 0; i < message.otelDataList.length; i++) - Struct.internalBinaryWrite(message.otelDataList[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message tfc.tracer.CreateOtelSpanRequest - */ -export const CreateOtelSpanRequest = new CreateOtelSpanRequest$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class CreateOtelSpanResponse$Type extends MessageType { - constructor() { - super("tfc.tracer.CreateOtelSpanResponse", [ - { no: 1, name: "ids", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ } - ]); - } - create(value?: PartialMessage): CreateOtelSpanResponse { - const message = globalThis.Object.create((this.messagePrototype!)); - message.ids = []; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: CreateOtelSpanResponse): CreateOtelSpanResponse { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* repeated string ids */ 1: - message.ids.push(reader.string()); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: CreateOtelSpanResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* repeated string ids = 1; */ - for (let i = 0; i < message.ids.length; i++) - writer.tag(1, WireType.LengthDelimited).string(message.ids[i]); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message tfc.tracer.CreateOtelSpanResponse - */ -export const CreateOtelSpanResponse = new CreateOtelSpanResponse$Type(); -/** - * @generated ServiceType for protobuf service tfc.tracer.ObservationSpanController - */ -export const ObservationSpanController = new ServiceType("tfc.tracer.ObservationSpanController", [ - { name: "CreateOtelSpan", options: {}, I: CreateOtelSpanRequest, O: CreateOtelSpanResponse } -]); diff --git a/typescript/packages/fi-core/src/grpc/tracer.proto b/typescript/packages/fi-core/src/grpc/tracer.proto deleted file mode 100644 index 5ca40776b..000000000 --- a/typescript/packages/fi-core/src/grpc/tracer.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package tfc.tracer; - -import "google/protobuf/struct.proto"; - -service ObservationSpanController { - rpc CreateOtelSpan(CreateOtelSpanRequest) returns (CreateOtelSpanResponse) {} -} - -message CreateOtelSpanRequest { - repeated google.protobuf.Struct otel_data_list = 1; -} - -message CreateOtelSpanResponse { - repeated string ids = 1; -} - diff --git a/typescript/packages/fi-core/src/otel.ts b/typescript/packages/fi-core/src/otel.ts index db18d5ced..94caef1f8 100644 --- a/typescript/packages/fi-core/src/otel.ts +++ b/typescript/packages/fi-core/src/otel.ts @@ -24,14 +24,9 @@ import { import { Resource, resourceFromAttributes, detectResources, defaultResource } from "@opentelemetry/resources"; import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions"; import { v4 as uuidv4 } from "uuid"; // For UUID generation + +// Import grpc for metadata handling import * as grpc from "@grpc/grpc-js"; -import { - CreateOtelSpanRequest, - CreateOtelSpanResponse, - ObservationSpanControllerClient -} from "./generated"; -import { GrpcTransport } from "@protobuf-ts/grpc-transport"; -import { Struct } from "./generated/google/protobuf/struct"; // --- Constants for Resource Attributes --- export const PROJECT_NAME = "project_name"; @@ -222,169 +217,50 @@ class HTTPSpanExporter implements SpanExporter { // --- Custom GRPCSpanExporter extending OTLP gRPC exporter --- class GRPCSpanExporter extends _OTLPGRPCTraceExporter { private verbose: boolean; - private client: ObservationSpanControllerClient | null = null; - private originalEndpoint: string; - private customHeaders: FIHeaders; - constructor(options: { endpoint: string; headers?: FIHeaders; verbose?: boolean }) { - const { endpoint, headers = {}, verbose = false } = options; - - // Since we completely override export(), pass empty config to super() - super({}); + constructor(options: { endpoint: string; headers?: FIHeaders; verbose?: boolean; [key: string]: any }) { + const { endpoint, headers = {}, verbose = false, ...restOptions } = options; - // Store original endpoint for our custom logic - this.originalEndpoint = endpoint.replace(/^https?:\/\//, ''); - this.customHeaders = headers; - this.verbose = verbose; - } + const auth_header = headers; + const lower_case_auth_header = auth_header + ? Object.fromEntries(Object.entries(auth_header).map(([k, v]) => [k.toLowerCase(), v])) + : {}; + + const metadata = new grpc.Metadata(); + Object.entries(lower_case_auth_header).forEach(([key, value]) => { + metadata.set(key, value); + }); - private getClient(): ObservationSpanControllerClient { - if (!this.client) { - // Default to insecure credentials (matching Python implementation) - // Most gRPC servers, even remote ones, often use insecure connections - const credentials = grpc.credentials.createInsecure(); - - if (this.verbose) { - diag.info(`GRPCSpanExporter: Connecting to ${this.originalEndpoint} with insecure credentials`); - } - - const transport = new GrpcTransport({ - host: this.originalEndpoint, - channelCredentials: credentials, - meta: this.customHeaders, - }); - this.client = new ObservationSpanControllerClient(transport); - } - return this.client; - } + const grpcConfig = { + url: endpoint, + metadata: metadata, + ...(endpoint.includes('localhost') || endpoint.includes('127.0.0.1') ? { + credentials: grpc.credentials.createInsecure() + } : {}), + ...restOptions, + }; - private convertAttributes(attributes: Attributes | undefined): Record { - if (!attributes) { - return {}; - } try { - return JSON.parse(JSON.stringify(attributes)); - } catch (e) { - diag.error(`GRPCSpanExporter: Error converting attributes: ${e}`); - return {}; - } - } - - private getSpanStatusName(status: SpanStatus): string { - switch (status.code) { - case SpanStatusCode.UNSET: - return "UNSET"; - case SpanStatusCode.OK: - return "OK"; - case SpanStatusCode.ERROR: - return "ERROR"; - default: - return "UNKNOWN"; - } - } - - export( - spans: ReadableSpan[], - resultCallback: (result: ExportResult) => void, - ): void { - if (!spans || !resultCallback) { - resultCallback?.({ code: ExportResultCode.FAILED }); - return; + super(grpcConfig); + } catch (error) { + diag.error(`GRPCSpanExporter: Error initializing OTLP exporter:`, error); + throw error; } - - const spansData = spans.map((span) => { - if (!span) return null; - const spanContext = span.spanContext(); - if (!spanContext) { - return null; - } - const parentSpanId = span.parentSpanContext?.spanId || undefined; - - const spanData = { - trace_id: spanContext.traceId, - span_id: spanContext.spanId, - name: span.name || "unknown-span", - start_time: span.startTime?.[0] * 1e9 + span.startTime?.[1] || 0, - end_time: span.endTime?.[0] * 1e9 + span.endTime?.[1] || 0, - attributes: this.convertAttributes(span.attributes), - events: span.events.map((event) => ({ - name: event.name, - attributes: this.convertAttributes(event.attributes), - timestamp: event.time[0] * 1e9 + event.time[1], - })), - status: this.getSpanStatusName(span.status), - parent_id: parentSpanId, - project_name: span.resource?.attributes[PROJECT_NAME], - project_type: span.resource?.attributes[PROJECT_TYPE], - project_version_name: span.resource?.attributes[PROJECT_VERSION_NAME], - project_version_id: span.resource?.attributes[PROJECT_VERSION_ID], - latency: Math.floor( - (span.endTime[0] * 1e9 + - span.endTime[1] - - (span.startTime[0] * 1e9 + span.startTime[1])) / - 1e6, - ), - eval_tags: span.resource?.attributes[EVAL_TAGS], - metadata: span.resource?.attributes[METADATA], - session_name: span.resource?.attributes[SESSION_NAME], - }; - - // Clean up undefined values and convert to Struct - const cleanSpanData: Record = {}; - Object.entries(spanData).forEach(([key, value]) => { - if (value !== undefined && value !== null) { - cleanSpanData[key] = value; - } - }); - - // Convert to Struct using proper protobuf method - return Struct.fromJson(cleanSpanData); - }).filter(Boolean) as Struct[]; - + + this.verbose = verbose; + if (this.verbose) { - diag.info("GRPCSpanExporter: Sending gRPC payload with", spansData.length, "spans"); - } - - const request = CreateOtelSpanRequest.create({ - otelDataList: spansData, - }); - - try { - const client = this.getClient(); - const startTime = Date.now(); - - if (this.verbose) { - diag.info("GRPCSpanExporter: Starting gRPC export..."); - } - - client.createOtelSpan(request) - .then((response) => { - const endTime = Date.now(); - if (this.verbose) { - diag.info(`GRPCSpanExporter: Export completed in ${endTime - startTime}ms`); - } - resultCallback({ code: ExportResultCode.SUCCESS }); - }) - .catch((error) => { - diag.error(`GRPCSpanExporter: Failed to export spans: ${error}`); - resultCallback({ code: ExportResultCode.FAILED }); - }); - } catch (error) { - diag.error(`GRPCSpanExporter: Error exporting spans: ${error}`); - resultCallback({ code: ExportResultCode.FAILED }); + diag.info(`GRPCSpanExporter: Configured for endpoint: ${endpoint}`); + diag.info(`GRPCSpanExporter: Authentication: ${Object.keys(lower_case_auth_header).length > 0 ? 'Enabled' : 'None'}`); } } async shutdown(): Promise { - if (this.client) { - this.client = null; + if (this.verbose) { + diag.info("GRPCSpanExporter: Shutting down..."); } return super.shutdown(); } - - async forceFlush(): Promise { - return super.forceFlush(); - } } // --- Helper Functions --- @@ -404,15 +280,15 @@ function getEnvFiAuthHeader(): FIHeaders | undefined { const apiKey = getEnv("FI_API_KEY"); const secretKey = getEnv("FI_SECRET_KEY"); if (apiKey && secretKey) { - // Match Python SDK: use X-Api-Key and X-Secret-Key headers - return { "X-Api-Key": apiKey, "X-Secret-Key": secretKey }; + // Use lowercase headers for gRPC compatibility + return { "x-api-key": apiKey, "x-secret-key": secretKey }; } return undefined; } function getEnvGrpcCollectorEndpoint(): string { let endpoint = getEnv("FI_GRPC_COLLECTOR_ENDPOINT") ?? - getEnv("FI_GRPC_BASE_URL") ?? + getEnv("FI_GRPC_URL") ?? DEFAULT_FI_GRPC_COLLECTOR_BASE_URL; // Remove http:// or https:// prefix if present (gRPC doesn't use HTTP protocol prefix) diff --git a/typescript/packages/fi-semantic-conventions/package.json b/typescript/packages/fi-semantic-conventions/package.json index 310dd3067..a4cb439cf 100644 --- a/typescript/packages/fi-semantic-conventions/package.json +++ b/typescript/packages/fi-semantic-conventions/package.json @@ -1,6 +1,6 @@ { "name": "@traceai/fi-semantic-conventions", - "version": "0.1.8", + "version": "0.1.9", "description": "Semantic conventions for OpenTelemetry instrumentation", "main": "./dist/src/index.js", "module": "./dist/esm/index.js", diff --git a/typescript/packages/traceai_anthropic/package.json b/typescript/packages/traceai_anthropic/package.json index 937568882..924144aa6 100644 --- a/typescript/packages/traceai_anthropic/package.json +++ b/typescript/packages/traceai_anthropic/package.json @@ -1,6 +1,6 @@ { "name": "@traceai/anthropic", - "version": "0.1.1", + "version": "0.1.2", "description": "OpenTelemetry instrumentation for Anthropic", "main": "./dist/src/index.js", "module": "./dist/esm/index.js", @@ -37,8 +37,8 @@ "dependencies": { "@opentelemetry/api": "^1.9.0", "@opentelemetry/instrumentation": "^0.202.0", - "@traceai/fi-core": "^0.1.10", - "@traceai/fi-semantic-conventions": "^0.1.8" + "@traceai/fi-core": "^0.1.13", + "@traceai/fi-semantic-conventions": "^0.1.9" }, "peerDependencies": { "@anthropic-ai/sdk": "^0.27.3" diff --git a/typescript/packages/traceai_openai/package.json b/typescript/packages/traceai_openai/package.json index 19993c58f..bb2ba2f20 100644 --- a/typescript/packages/traceai_openai/package.json +++ b/typescript/packages/traceai_openai/package.json @@ -1,6 +1,6 @@ { "name": "@traceai/openai", - "version": "0.1.12", + "version": "0.1.13", "description": "OpenTelemetry instrumentation for OpenAI", "main": "./dist/src/index.js", "module": "./dist/esm/index.js", @@ -36,10 +36,9 @@ "homepage": "https://github.com/future-agi/traceAI/tree/main/typescript/packages/traceai_openai#readme", "dependencies": { "@opentelemetry/api": "^1.9.0", - "@opentelemetry/core": "^2.0.1", "@opentelemetry/instrumentation": "^0.202.0", - "@traceai/fi-core": "^0.1.11", - "@traceai/fi-semantic-conventions": "^0.1.8" + "@traceai/fi-core": "^0.1.13", + "@traceai/fi-semantic-conventions": "^0.1.9" }, "peerDependencies": { "openai": "^4.0.0 || ^5.0.0"