1717import logging
1818import os
1919import sys
20+ import warnings
2021from typing import Any , Dict , Optional
2122
2223import sentry_sdk
2324from colorama import Fore
2425from opentelemetry import trace
25- from opentelemetry .exporter .otlp .proto .grpc .trace_exporter import \
26- OTLPSpanExporter as GRPCExporter
27- from opentelemetry .exporter .otlp .proto .http .trace_exporter import \
28- OTLPSpanExporter as HTTPExporter
26+ from opentelemetry .exporter .otlp .proto .grpc .trace_exporter import (
27+ OTLPSpanExporter as GRPCExporter ,
28+ )
29+ from opentelemetry .exporter .otlp .proto .http .trace_exporter import (
30+ OTLPSpanExporter as HTTPExporter ,
31+ )
2932from opentelemetry .instrumentation .sqlalchemy import SQLAlchemyInstrumentor
3033from opentelemetry .sdk .resources import SERVICE_NAME , Resource
3134from opentelemetry .sdk .trace import TracerProvider
32- from opentelemetry .sdk .trace .export import (BatchSpanProcessor ,
33- ConsoleSpanExporter ,
34- SimpleSpanProcessor )
35+ from opentelemetry .sdk .trace .export import (
36+ BatchSpanProcessor ,
37+ ConsoleSpanExporter ,
38+ SimpleSpanProcessor ,
39+ )
3540from opentelemetry .util .re import parse_env_headers
3641from sentry_sdk .types import Event , Hint
3742
3843from langtrace_python_sdk .constants import LANGTRACE_SDK_NAME , SENTRY_DSN
3944from langtrace_python_sdk .constants .exporter .langtrace_exporter import (
40- LANGTRACE_REMOTE_URL , LANGTRACE_SESSION_ID_HEADER )
41- from langtrace_python_sdk .extensions .langtrace_exporter import \
42- LangTraceExporter
45+ LANGTRACE_REMOTE_URL ,
46+ LANGTRACE_SESSION_ID_HEADER ,
47+ )
48+ from langtrace_python_sdk .extensions .langtrace_exporter import LangTraceExporter
4349from langtrace_python_sdk .instrumentation import (
44- AgnoInstrumentation , AnthropicInstrumentation , AutogenInstrumentation ,
45- AWSBedrockInstrumentation , CerebrasInstrumentation , ChromaInstrumentation ,
46- CleanLabInstrumentation , CohereInstrumentation , CrewAIInstrumentation ,
47- CrewaiToolsInstrumentation , DspyInstrumentation , EmbedchainInstrumentation ,
48- GeminiInstrumentation , GoogleGenaiInstrumentation , GraphlitInstrumentation ,
49- GroqInstrumentation , LangchainCommunityInstrumentation ,
50- LangchainCoreInstrumentation , LangchainInstrumentation , LanggraphInstrumentation ,
51- LiteLLMInstrumentation , LlamaindexInstrumentation , MilvusInstrumentation ,
52- MistralInstrumentation , Neo4jInstrumentation , Neo4jGraphRAGInstrumentation ,
53- OllamaInstrumentor , OpenAIAgentsInstrumentation , OpenAIInstrumentation ,
54- PhiDataInstrumentation , PineconeInstrumentation , PyMongoInstrumentation ,
55- QdrantInstrumentation , VertexAIInstrumentation , WeaviateInstrumentation )
56- from langtrace_python_sdk .types import (DisableInstrumentations ,
57- InstrumentationMethods )
58- from langtrace_python_sdk .utils import (check_if_sdk_is_outdated ,
59- get_sdk_version , is_package_installed ,
60- validate_instrumentations )
50+ AgnoInstrumentation ,
51+ AnthropicInstrumentation ,
52+ AutogenInstrumentation ,
53+ AWSBedrockInstrumentation ,
54+ CerebrasInstrumentation ,
55+ ChromaInstrumentation ,
56+ CleanLabInstrumentation ,
57+ CohereInstrumentation ,
58+ CrewAIInstrumentation ,
59+ CrewaiToolsInstrumentation ,
60+ DspyInstrumentation ,
61+ EmbedchainInstrumentation ,
62+ GeminiInstrumentation ,
63+ GoogleGenaiInstrumentation ,
64+ GraphlitInstrumentation ,
65+ GroqInstrumentation ,
66+ LangchainCommunityInstrumentation ,
67+ LangchainCoreInstrumentation ,
68+ LangchainInstrumentation ,
69+ LanggraphInstrumentation ,
70+ LiteLLMInstrumentation ,
71+ LlamaindexInstrumentation ,
72+ MilvusInstrumentation ,
73+ MistralInstrumentation ,
74+ Neo4jInstrumentation ,
75+ Neo4jGraphRAGInstrumentation ,
76+ OllamaInstrumentor ,
77+ OpenAIAgentsInstrumentation ,
78+ OpenAIInstrumentation ,
79+ PhiDataInstrumentation ,
80+ PineconeInstrumentation ,
81+ PyMongoInstrumentation ,
82+ QdrantInstrumentation ,
83+ VertexAIInstrumentation ,
84+ WeaviateInstrumentation ,
85+ )
86+ from langtrace_python_sdk .types import DisableInstrumentations , InstrumentationMethods
87+ from langtrace_python_sdk .utils import (
88+ check_if_sdk_is_outdated ,
89+ get_sdk_version ,
90+ is_package_installed ,
91+ validate_instrumentations ,
92+ )
6193from langtrace_python_sdk .utils .langtrace_sampler import LangtraceSampler
6294
6395
@@ -173,7 +205,30 @@ def add_span_processor(provider: TracerProvider, config: LangtraceConfig, export
173205 )
174206 else :
175207 provider .add_span_processor (BatchSpanProcessor (exporter ))
176- print (Fore .BLUE + "Exporting spans to Langtrace cloud.." + Fore .RESET )
208+ project = get_project (config )
209+ if project :
210+ print (Fore .BLUE + f"Exporting spans to { project ['name' ]} .." + Fore .RESET )
211+ print (
212+ Fore .BLUE
213+ + f"Langtrace Project URL: { LANGTRACE_REMOTE_URL } /project/{ project ['id' ]} /traces"
214+ + Fore .RESET
215+ )
216+ else :
217+ print (Fore .BLUE + "Exporting spans to Langtrace cloud.." + Fore .RESET )
218+
219+
220+ def get_project (config : LangtraceConfig ):
221+ import requests
222+
223+ try :
224+
225+ response = requests .get (
226+ f"{ LANGTRACE_REMOTE_URL } /api/project" ,
227+ headers = {"x-api-key" : config .api_key },
228+ )
229+ return response .json ()["project" ]
230+ except Exception as error :
231+ return None
177232
178233
179234def init_sentry (config : LangtraceConfig , host : str ):
@@ -329,6 +384,8 @@ def init_instrumentations(
329384 if is_package_installed (name ):
330385 try :
331386 v .instrument ()
387+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
388+ warnings .filterwarnings ("ignore" , category = UserWarning )
332389 except Exception as e :
333390 print (f"Skipping { name } due to error while instrumenting: { e } " )
334391
@@ -354,5 +411,7 @@ def init_instrumentations(
354411 if is_package_installed (name ):
355412 try :
356413 v .instrument ()
414+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
415+ warnings .filterwarnings ("ignore" , category = UserWarning )
357416 except Exception as e :
358417 print (f"Skipping { name } due to error while instrumenting: { e } " )
0 commit comments