Skip to content

Commit b91c347

Browse files
committed
merge
2 parents 0abf70b + 00370f5 commit b91c347

File tree

3 files changed

+94
-31
lines changed

3 files changed

+94
-31
lines changed

src/langtrace_python_sdk/instrumentation/neo4j/patch.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737

3838
def driver_patch(operation_name, version, tracer):
3939
def traced_method(wrapped, instance, args, kwargs):
40-
40+
try:
41+
query = args[0].text if hasattr(args[0], "text") else args[0]
42+
query_text = json.dumps(query)
43+
except (AttributeError, TypeError):
44+
query_text = args[0]
4145
api = APIS[operation_name]
4246
service_provider = SERVICE_PROVIDERS.get("NEO4J", "neo4j")
4347
extra_attributes = baggage.get_baggage(LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY)
@@ -49,7 +53,7 @@ def traced_method(wrapped, instance, args, kwargs):
4953
"langtrace.version": v(LANGTRACE_SDK_NAME),
5054
"db.system": "neo4j",
5155
"db.operation": api["OPERATION"],
52-
"db.query": json.dumps(args[0]) if args and len(args) > 0 else "",
56+
"db.query": query_text,
5357
**(extra_attributes if extra_attributes is not None else {}),
5458
}
5559

src/langtrace_python_sdk/langtrace.py

Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,79 @@
1717
import logging
1818
import os
1919
import sys
20+
import warnings
2021
from typing import Any, Dict, Optional
2122

2223
import sentry_sdk
2324
from colorama import Fore
2425
from 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+
)
2932
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
3033
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
3134
from 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+
)
3540
from opentelemetry.util.re import parse_env_headers
3641
from sentry_sdk.types import Event, Hint
3742

3843
from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME, SENTRY_DSN
3944
from 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
4349
from 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+
)
6193
from 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

179234
def 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}")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.8.11"
1+
__version__ = "3.8.14"

0 commit comments

Comments
 (0)