langtrace-python-sdk 1.0.11__py3-none-any.whl → 1.0.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. constants/instrumentation/chroma.py +40 -0
  2. instrumentation/constants.py → constants/instrumentation/common.py +9 -4
  3. instrumentation/openai/constants.py → constants/instrumentation/openai.py +16 -10
  4. instrumentation/pinecone/apis.py → constants/instrumentation/pinecone.py +1 -1
  5. examples/chroma_example/__init__.py +1 -0
  6. examples/chroma_example/basic.py +3 -4
  7. examples/langchain_example/basic.py +3 -4
  8. examples/langchain_example/tool.py +3 -3
  9. examples/llamaindex_example/basic.py +4 -3
  10. examples/openai/chat_completion.py +4 -3
  11. examples/openai/embeddings_create.py +4 -4
  12. examples/openai/function_calling.py +4 -3
  13. examples/openai/images_generate.py +3 -3
  14. examples/pinecone_example/basic.py +3 -3
  15. extensions/langtrace_exporter.py +75 -0
  16. init/__init__.py +1 -0
  17. init/init.py +72 -0
  18. instrumentation/chroma/instrumentation.py +1 -1
  19. instrumentation/chroma/patch.py +2 -2
  20. instrumentation/langchain/patch.py +1 -1
  21. instrumentation/langchain_community/patch.py +2 -1
  22. instrumentation/langchain_core/patch.py +2 -1
  23. instrumentation/llamaindex/patch.py +2 -1
  24. instrumentation/openai/patch.py +5 -5
  25. instrumentation/openai/token_estimation.py +2 -3
  26. instrumentation/pinecone/instrumentation.py +1 -1
  27. instrumentation/pinecone/patch.py +2 -2
  28. {langtrace_python_sdk-1.0.11.dist-info → langtrace_python_sdk-1.0.12.dist-info}/METADATA +5 -3
  29. langtrace_python_sdk-1.0.12.dist-info/RECORD +56 -0
  30. langtrace_python_sdk-1.0.12.dist-info/top_level.txt +6 -0
  31. utils/__init__.py +0 -0
  32. examples/setup.py +0 -50
  33. instrumentation/openai/apis.py +0 -19
  34. langtrace_python_sdk-1.0.11.dist-info/RECORD +0 -53
  35. langtrace_python_sdk-1.0.11.dist-info/top_level.txt +0 -2
  36. {instrumentation/chroma/lib → constants}/__init__.py +0 -0
  37. {instrumentation/openai/lib → constants/instrumentation}/__init__.py +0 -0
  38. {instrumentation/pinecone/lib → extensions}/__init__.py +0 -0
  39. {langtrace_python_sdk-1.0.11.dist-info → langtrace_python_sdk-1.0.12.dist-info}/LICENSE +0 -0
  40. {langtrace_python_sdk-1.0.11.dist-info → langtrace_python_sdk-1.0.12.dist-info}/WHEEL +0 -0
  41. {instrumentation → utils}/with_root_span.py +0 -0
@@ -0,0 +1,40 @@
1
+ from langtrace.trace_attributes import ChromaDBMethods
2
+
3
+ APIS = {
4
+ "ADD": {
5
+ "METHOD": ChromaDBMethods.ADD.value,
6
+ "OPERATION": "add",
7
+ },
8
+ "GET": {
9
+ "METHOD": ChromaDBMethods.GET.value,
10
+ "OPERATION": "get",
11
+ },
12
+ "QUERY": {
13
+ "METHOD": ChromaDBMethods.QUERY.value,
14
+ "OPERATION": "query",
15
+ },
16
+ "DELETE": {
17
+ "METHOD": ChromaDBMethods.DELETE.value,
18
+ "OPERATION": "delete",
19
+ },
20
+ "PEEK": {
21
+ "METHOD": ChromaDBMethods.PEEK.value,
22
+ "OPERATION": "peek",
23
+ },
24
+ "UPDATE": {
25
+ "METHOD": ChromaDBMethods.UPDATE.value,
26
+ "OPERATION": "update",
27
+ },
28
+ "UPSERT": {
29
+ "METHOD": ChromaDBMethods.UPSERT.value,
30
+ "OPERATION": "upsert",
31
+ },
32
+ "MODIFY": {
33
+ "METHOD": ChromaDBMethods.MODIFY.value,
34
+ "OPERATION": "modify",
35
+ },
36
+ "COUNT": {
37
+ "METHOD": ChromaDBMethods.COUNT.value,
38
+ "OPERATION": "count",
39
+ },
40
+ }
@@ -1,6 +1,11 @@
1
- """
2
- This file contains the constants used in the project.
3
- """
1
+ TIKTOKEN_MODEL_MAPPING = {
2
+ "gpt-4": "cl100k_base",
3
+ "gpt-4-32k": "cl100k_base",
4
+ "gpt-4-0125-preview": "cl100k_base",
5
+ "gpt-4-1106-preview": "cl100k_base",
6
+ "gpt-4-1106-vision-preview": "cl100k_base",
7
+ }
8
+
4
9
  SERVICE_PROVIDERS = {
5
10
  "OPENAI": "OpenAI",
6
11
  "AZURE": "Azure",
@@ -10,4 +15,4 @@ SERVICE_PROVIDERS = {
10
15
  "PINECONE": "Pinecone",
11
16
  "LLAMAINDEX": "LlamaIndex",
12
17
  "CHROMA": "Chroma",
13
- }
18
+ }
@@ -1,5 +1,4 @@
1
- """
2
- Constants for OpenAI API"""
1
+ from langtrace.trace_attributes import OpenAIMethods
3
2
 
4
3
  OPENAI_COST_TABLE = {
5
4
  "gpt-4-0125-preview": {
@@ -32,12 +31,19 @@ OPENAI_COST_TABLE = {
32
31
  },
33
32
  }
34
33
 
35
- # TODO: Add more models
36
- # https://github.com/dqbd/tiktoken/blob/74c147e19584a3a1acea0c8e0da4d39415cd33e0/wasm/src/lib.rs#L328
37
- TIKTOKEN_MODEL_MAPPING = {
38
- "gpt-4": "cl100k_base",
39
- "gpt-4-32k": "cl100k_base",
40
- "gpt-4-0125-preview": "cl100k_base",
41
- "gpt-4-1106-preview": "cl100k_base",
42
- "gpt-4-1106-vision-preview": "cl100k_base",
34
+ APIS = {
35
+ "CHAT_COMPLETION": {
36
+ "METHOD": OpenAIMethods.CHAT_COMPLETION.value,
37
+ "ENDPOINT": "/chat/completions",
38
+ },
39
+ "IMAGES_GENERATION": {
40
+ "METHOD": OpenAIMethods.IMAGES_GENERATION.value,
41
+ "ENDPOINT": "/images/generations",
42
+ },
43
+ "EMBEDDINGS_CREATE": {
44
+ "METHOD": OpenAIMethods.EMBEDDINGS_CREATE.value,
45
+ "ENDPOINT": "/embeddings",
46
+ },
43
47
  }
48
+
49
+
@@ -12,7 +12,7 @@ APIS = {
12
12
  "OPERATION": "query",
13
13
  },
14
14
  "DELETE": {
15
- "METHOD": PineconeMethods.DELETE.value,
15
+ "METHOD": PineconeMethods.DELETE,
16
16
  "ENDPOINT": "/vectors/delete",
17
17
  "OPERATION": "delete",
18
18
  }
@@ -0,0 +1 @@
1
+ from .basic import basic
@@ -2,12 +2,11 @@ import chromadb
2
2
  from chromadb.utils import embedding_functions
3
3
  from dotenv import find_dotenv, load_dotenv
4
4
 
5
- from examples.setup import setup_instrumentation
6
- from instrumentation.with_root_span import with_langtrace_root_span
7
-
5
+ from utils.with_root_span import with_langtrace_root_span
6
+ from init import init
8
7
  _ = load_dotenv(find_dotenv())
9
8
 
10
- setup_instrumentation()
9
+ init()
11
10
 
12
11
 
13
12
  @with_langtrace_root_span()
@@ -1,4 +1,5 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
+ from init.init import init
2
3
  from langchain.text_splitter import RecursiveCharacterTextSplitter
3
4
  from langchain_community.document_loaders import PyPDFLoader
4
5
  from langchain_community.vectorstores.faiss import FAISS
@@ -6,14 +7,12 @@ from langchain_core.output_parsers import StrOutputParser
6
7
  from langchain_core.prompts.chat import ChatPromptTemplate
7
8
  from langchain_core.runnables import RunnablePassthrough
8
9
  from langchain_openai import ChatOpenAI, OpenAIEmbeddings
10
+ from utils.with_root_span import with_langtrace_root_span
9
11
 
10
- from examples.setup import setup_instrumentation
11
- from instrumentation.with_root_span import with_langtrace_root_span
12
12
 
13
13
  _ = load_dotenv(find_dotenv())
14
14
 
15
- setup_instrumentation()
16
-
15
+ init()
17
16
 
18
17
  @with_langtrace_root_span()
19
18
  def basic():
@@ -1,17 +1,17 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
+ from init import init
2
3
  from langchain import hub
3
4
  from langchain.agents import AgentExecutor, create_openai_functions_agent
4
5
  from langchain.chains import LLMMathChain
5
6
  from langchain_core.pydantic_v1 import BaseModel, Field
6
7
  from langchain_core.tools import Tool
7
8
  from langchain_openai import ChatOpenAI
9
+ from utils.with_root_span import with_langtrace_root_span
8
10
 
9
- from examples.setup import setup_instrumentation
10
- from instrumentation.with_root_span import with_langtrace_root_span
11
11
 
12
12
  _ = load_dotenv(find_dotenv())
13
13
 
14
- setup_instrumentation()
14
+ init()
15
15
 
16
16
 
17
17
  llm = ChatOpenAI(temperature=0, model="gpt-4")
@@ -1,12 +1,13 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
+ from init import init
2
3
  from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
4
+ from utils.with_root_span import with_langtrace_root_span
3
5
 
4
- from examples.setup import setup_instrumentation
5
- from instrumentation.with_root_span import with_langtrace_root_span
6
6
 
7
7
  _ = load_dotenv(find_dotenv())
8
8
 
9
- setup_instrumentation()
9
+
10
+ init()
10
11
 
11
12
 
12
13
  @with_langtrace_root_span()
@@ -1,12 +1,13 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
2
  from openai import OpenAI
3
3
 
4
- from examples.setup import setup_instrumentation
5
- from instrumentation.with_root_span import with_langtrace_root_span
4
+ from init.init import init
5
+ from utils.with_root_span import with_langtrace_root_span
6
+
6
7
 
7
8
  _ = load_dotenv(find_dotenv())
8
9
 
9
- setup_instrumentation()
10
+ init()
10
11
 
11
12
  client = OpenAI()
12
13
 
@@ -1,13 +1,13 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
+ from init import init
2
3
  from openai import OpenAI
3
4
 
4
- from examples.setup import setup_instrumentation
5
- from instrumentation.with_root_span import with_langtrace_root_span
5
+ from utils.with_root_span import with_langtrace_root_span
6
6
 
7
- _ = load_dotenv(find_dotenv())
8
7
 
9
- setup_instrumentation()
8
+ _ = load_dotenv(find_dotenv())
10
9
 
10
+ init()
11
11
  client = OpenAI()
12
12
 
13
13
 
@@ -1,14 +1,15 @@
1
1
  import json
2
2
 
3
3
  from dotenv import find_dotenv, load_dotenv
4
+ from init import init
4
5
  from openai import OpenAI
5
6
 
6
- from examples.setup import setup_instrumentation
7
- from instrumentation.with_root_span import with_langtrace_root_span
7
+ from utils.with_root_span import with_langtrace_root_span
8
+
8
9
 
9
10
  _ = load_dotenv(find_dotenv())
10
11
 
11
- setup_instrumentation()
12
+ init()
12
13
 
13
14
  client = OpenAI()
14
15
 
@@ -1,12 +1,12 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
+ from init import init
2
3
  from openai import OpenAI
4
+ from utils.with_root_span import with_langtrace_root_span
3
5
 
4
- from examples.setup import setup_instrumentation
5
- from instrumentation.with_root_span import with_langtrace_root_span
6
6
 
7
7
  _ = load_dotenv(find_dotenv())
8
8
 
9
- setup_instrumentation()
9
+ init()
10
10
 
11
11
  client = OpenAI()
12
12
 
@@ -1,13 +1,13 @@
1
1
  from dotenv import find_dotenv, load_dotenv
2
+ from init import init
2
3
  from openai import OpenAI
3
4
  from pinecone import Pinecone
5
+ from utils.with_root_span import with_langtrace_root_span
4
6
 
5
- from examples.setup import setup_instrumentation
6
- from instrumentation.with_root_span import with_langtrace_root_span
7
7
 
8
8
  _ = load_dotenv(find_dotenv())
9
9
 
10
- setup_instrumentation()
10
+ init()
11
11
 
12
12
  client = OpenAI()
13
13
  pinecone = Pinecone()
@@ -0,0 +1,75 @@
1
+ import json
2
+ from opentelemetry.sdk.trace.export import (SpanExporter, ReadableSpan, SpanExportResult)
3
+ import os
4
+ import typing
5
+ import requests
6
+
7
+
8
+
9
+
10
+ class LangTraceExporter(SpanExporter):
11
+ api_key: str
12
+ url: str
13
+ write_to_remote_url: bool
14
+
15
+ def __init__(self, api_key: str = None, url: str = None, write_to_remote_url: bool = False) -> None:
16
+ self.api_key = api_key if api_key else os.environ.get('LANGTRACE_API_KEY')
17
+ self.url = url if url else os.environ.get('LANGTRACE_URL')
18
+ self.write_to_remote_url = write_to_remote_url
19
+
20
+ if not self.api_key:
21
+ raise ValueError('No API key provided')
22
+
23
+ if not self.url and self.write_to_remote_url:
24
+ raise ValueError('No URL provided')
25
+
26
+ def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
27
+
28
+ """
29
+ Exports a batch of telemetry data.
30
+
31
+ Args:
32
+ spans: The list of `opentelemetry.trace.Span` objects to be exported
33
+
34
+ Returns:
35
+ The result of the export SUCCESS or FAILURE
36
+ """
37
+
38
+
39
+ data = [
40
+ {
41
+ 'traceId': span.get_span_context().trace_id,
42
+ 'instrumentationLibrary': span.instrumentation_info.__repr__(),
43
+ 'droppedEventsCount': span.dropped_events,
44
+ 'droppedAttributesCount': span.dropped_attributes,
45
+ 'droppedLinksCount': span.dropped_links,
46
+ 'ended': span.status.is_ok,
47
+ 'duration': span.end_time - span.start_time,
48
+ **json.loads(span.to_json()),
49
+ } for span in spans]
50
+
51
+
52
+ if not self.write_to_remote_url:
53
+ return
54
+
55
+ # Send data to remote URL
56
+ try:
57
+ requests.post(
58
+ url=self.url,
59
+ data=json.dumps(data),
60
+ headers={
61
+ 'Content-Type': 'application/json',
62
+ 'x-api-key': self.api_key
63
+ }
64
+ )
65
+ print(f"Sent To {self.url} with Body {data} ")
66
+ return SpanExportResult.SUCCESS
67
+ except Exception as e:
68
+ print("Error sending data to remote URL", e)
69
+ return SpanExportResult.FAILURE
70
+
71
+
72
+
73
+
74
+ def shutdown(self) -> None:
75
+ pass
init/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from init.init import init
init/init.py ADDED
@@ -0,0 +1,72 @@
1
+ from opentelemetry.sdk.trace import TracerProvider
2
+ from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor, BatchSpanProcessor
3
+ from extensions.langtrace_exporter import LangTraceExporter
4
+
5
+ from instrumentation.chroma.instrumentation import ChromaInstrumentation
6
+ from instrumentation.langchain.instrumentation import LangchainInstrumentation
7
+ from instrumentation.langchain_community.instrumentation import \
8
+ LangchainCommunityInstrumentation
9
+ from instrumentation.langchain_core.instrumentation import \
10
+ LangchainCoreInstrumentation
11
+ from instrumentation.llamaindex.instrumentation import \
12
+ LlamaindexInstrumentation
13
+ from instrumentation.openai.instrumentation import OpenAIInstrumentation
14
+ from instrumentation.pinecone.instrumentation import PineconeInstrumentation
15
+ from opentelemetry import trace
16
+
17
+ def init(
18
+ api_key: str = None,
19
+ remote_url: str = None,
20
+ batch: bool = False,
21
+ log_spans_to_console: bool = False,
22
+ write_to_remote_url: bool = True
23
+ ):
24
+
25
+ provider = TracerProvider()
26
+ remote_write_exporter = LangTraceExporter(api_key, remote_url, write_to_remote_url)
27
+ console_exporter = ConsoleSpanExporter()
28
+ batch_processor_remote = BatchSpanProcessor(remote_write_exporter)
29
+ simple_processor_remote = SimpleSpanProcessor(remote_write_exporter)
30
+ batch_processor_console = BatchSpanProcessor(console_exporter)
31
+ simple_processor_console = SimpleSpanProcessor(console_exporter)
32
+
33
+ if log_spans_to_console:
34
+ if batch:
35
+ provider.add_span_processor(batch_processor_console)
36
+ else:
37
+ provider.add_span_processor(simple_processor_console)
38
+
39
+ if write_to_remote_url:
40
+ if batch:
41
+ provider.add_span_processor(batch_processor_remote)
42
+ else:
43
+ provider.add_span_processor(simple_processor_remote)
44
+
45
+
46
+ # Initialize tracer
47
+ trace.set_tracer_provider(provider)
48
+
49
+
50
+ openai_instrumentation = OpenAIInstrumentation()
51
+ pinecone_instrumentation = PineconeInstrumentation()
52
+ llamaindex_instrumentation = LlamaindexInstrumentation()
53
+ chroma_instrumentation = ChromaInstrumentation()
54
+ langchain_instrumentation = LangchainInstrumentation()
55
+ langchain_core_instrumentation = LangchainCoreInstrumentation()
56
+ langchain_community_instrumentation = LangchainCommunityInstrumentation()
57
+
58
+
59
+ # Call the instrument method with some arguments
60
+ openai_instrumentation.instrument()
61
+ pinecone_instrumentation.instrument()
62
+ llamaindex_instrumentation.instrument()
63
+ chroma_instrumentation.instrument()
64
+ langchain_instrumentation.instrument()
65
+ langchain_core_instrumentation.instrument()
66
+ langchain_community_instrumentation.instrument()
67
+
68
+
69
+
70
+
71
+
72
+
@@ -8,7 +8,7 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
8
8
  from opentelemetry.trace import get_tracer
9
9
  from wrapt import wrap_function_wrapper
10
10
 
11
- from instrumentation.chroma.apis import APIS
11
+ from constants.instrumentation.chroma import APIS
12
12
  from instrumentation.chroma.patch import collection_patch
13
13
 
14
14
 
@@ -5,8 +5,8 @@ from langtrace.trace_attributes import DatabaseSpanAttributes
5
5
  from opentelemetry.trace import SpanKind
6
6
  from opentelemetry.trace.status import Status, StatusCode
7
7
 
8
- from instrumentation.chroma.apis import APIS
9
- from instrumentation.constants import SERVICE_PROVIDERS
8
+ from constants.instrumentation.chroma import APIS
9
+ from constants.instrumentation.common import SERVICE_PROVIDERS
10
10
 
11
11
 
12
12
  def collection_patch(method, version, tracer):
@@ -7,7 +7,7 @@ from langtrace.trace_attributes import FrameworkSpanAttributes
7
7
  from opentelemetry.trace import SpanKind, StatusCode
8
8
  from opentelemetry.trace.status import Status
9
9
 
10
- from instrumentation.constants import SERVICE_PROVIDERS
10
+ from constants.instrumentation.common import SERVICE_PROVIDERS
11
11
 
12
12
 
13
13
  def generic_patch(method_name, task, tracer, version, trace_output=True, trace_input=True):
@@ -4,7 +4,8 @@ from langtrace.trace_attributes import FrameworkSpanAttributes
4
4
  from opentelemetry.trace import SpanKind, StatusCode
5
5
  from opentelemetry.trace.status import Status, StatusCode
6
6
 
7
- from instrumentation.constants import SERVICE_PROVIDERS
7
+ from constants.instrumentation.common import SERVICE_PROVIDERS
8
+
8
9
 
9
10
 
10
11
  def generic_patch(method_name, task, tracer, version, trace_output=True, trace_input=True):
@@ -7,7 +7,8 @@ from langtrace.trace_attributes import FrameworkSpanAttributes
7
7
  from opentelemetry.trace import SpanKind, StatusCode
8
8
  from opentelemetry.trace.status import Status
9
9
 
10
- from instrumentation.constants import SERVICE_PROVIDERS
10
+ from constants.instrumentation.common import SERVICE_PROVIDERS
11
+
11
12
 
12
13
 
13
14
  def generic_patch(method_name, task, tracer, version, trace_output=True, trace_input=True):
@@ -5,7 +5,8 @@ from langtrace.trace_attributes import FrameworkSpanAttributes
5
5
  from opentelemetry.trace import SpanKind
6
6
  from opentelemetry.trace.status import Status, StatusCode
7
7
 
8
- from instrumentation.constants import SERVICE_PROVIDERS
8
+ from constants.instrumentation.common import SERVICE_PROVIDERS
9
+
9
10
 
10
11
 
11
12
  def generic_patch(method, task, tracer, version):
@@ -6,8 +6,8 @@ from langtrace.trace_attributes import Event, LLMSpanAttributes
6
6
  from opentelemetry.trace import SpanKind
7
7
  from opentelemetry.trace.status import Status, StatusCode
8
8
 
9
- from instrumentation.constants import SERVICE_PROVIDERS
10
- from instrumentation.openai.apis import APIS
9
+ from constants.instrumentation.common import SERVICE_PROVIDERS
10
+ from constants.instrumentation.openai import APIS
11
11
  from instrumentation.openai.token_estimation import (calculate_prompt_tokens,
12
12
  estimate_tokens)
13
13
 
@@ -94,9 +94,9 @@ def chat_completions_create(original_method, version, tracer):
94
94
  attributes.llm_top_p = kwargs.get('top_p')
95
95
  if kwargs.get('user') is not None:
96
96
  attributes.llm_user = kwargs.get('user')
97
- if kwargs.get('functions') is not None:
98
- attributes.llm_function_prompts = json.dumps(
99
- kwargs.get('functions'))
97
+ # if kwargs.get('functions') is not None:
98
+ # attributes.llm_function_prompts = json.dumps(
99
+ # kwargs.get('functions'))
100
100
 
101
101
  # TODO(Karthik): Gotta figure out how to handle streaming with context
102
102
  # with tracer.start_as_current_span(APIS["CHAT_COMPLETION"]["METHOD"],
@@ -4,9 +4,8 @@ to calculate the price of a model based on its usage.
4
4
  """
5
5
 
6
6
  from tiktoken import get_encoding
7
-
8
- from instrumentation.openai.constants import (OPENAI_COST_TABLE,
9
- TIKTOKEN_MODEL_MAPPING)
7
+ from constants.instrumentation.openai import OPENAI_COST_TABLE
8
+ from constants.instrumentation.common import TIKTOKEN_MODEL_MAPPING
10
9
 
11
10
 
12
11
  def estimate_tokens(prompt):
@@ -11,7 +11,7 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
11
11
  from opentelemetry.trace import get_tracer
12
12
  from wrapt import wrap_function_wrapper
13
13
 
14
- from instrumentation.pinecone.apis import APIS
14
+ from constants.instrumentation.pinecone import APIS
15
15
  from instrumentation.pinecone.patch import generic_patch
16
16
 
17
17
 
@@ -4,8 +4,8 @@ from langtrace.trace_attributes import DatabaseSpanAttributes
4
4
  from opentelemetry.trace import SpanKind
5
5
  from opentelemetry.trace.status import Status, StatusCode
6
6
 
7
- from instrumentation.constants import SERVICE_PROVIDERS
8
- from instrumentation.pinecone.apis import APIS
7
+ from constants.instrumentation.common import SERVICE_PROVIDERS
8
+ from constants.instrumentation.pinecone import APIS
9
9
 
10
10
 
11
11
  def generic_patch(original_method, method, version, tracer):
@@ -1,10 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langtrace-python-sdk
3
- Version: 1.0.11
4
- Summary: LangTrace - Python SDK
3
+ Version: 1.0.12
4
+ Summary: Python SDK for LangTrace
5
5
  Home-page: https://github.com/Scale3-Labs/langtrace-python-sdk
6
- Author: Ali Waleed
6
+ Author: Scale3 Labs
7
7
  Author-email: ali@scale3labs.com
8
+ Maintainer: ['Karthik Kalyanaraman', 'Ali Waleed', 'Rohit Kadhe']
9
+ License: AGPL-3.0-or-later
8
10
  Classifier: Programming Language :: Python :: 3
9
11
  Classifier: License :: OSI Approved :: MIT License
10
12
  Classifier: Operating System :: OS Independent
@@ -0,0 +1,56 @@
1
+ constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ constants/instrumentation/chroma.py,sha256=hiPGYdHS0Yj4Kh3eaYBbuCAl_swqIygu80yFqkOgdak,955
4
+ constants/instrumentation/common.py,sha256=boc8W2xUXXwRqf7d8FNl2EmUXvSjbDju_QFY03nzbGw,493
5
+ constants/instrumentation/openai.py,sha256=wQ3vb7C3Okt7XJyxDfo9LWwtEggx8s9DzQ1JKPJ7pw8,1050
6
+ constants/instrumentation/pinecone.py,sha256=8RZpXA1Qs2aQd8L_1qpevloPGMdY-IIr_hjz3jVK3PY,471
7
+ examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ examples/chroma_example/__init__.py,sha256=ktveH9U1bkZwKUIqwGSJy_fPmIQ0dYwUuDRPUSY_s-k,24
9
+ examples/chroma_example/basic.py,sha256=6mT0l4KMDMJCrn8mwBCyetFaeGrpKy52uYCrOPGKhB4,781
10
+ examples/langchain_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ examples/langchain_example/basic.py,sha256=m2OtfaWwGbhTgClbDdoCpvYExOOUOZboBSFrKmPWzyM,1943
12
+ examples/langchain_example/tool.py,sha256=3g85yyGRoOmhNcbE16qsakODvhlQJxOB2gaggoFw1qc,2440
13
+ examples/llamaindex_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ examples/llamaindex_example/basic.py,sha256=OeOwv8lhY87dfmL8o4K69UCrgDTip41LwDe-BoxDf0I,567
15
+ examples/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ examples/openai/chat_completion.py,sha256=kxMoMR2DizU-QcgLbUv1xedCOM5q-wnftUfsfCAssec,1252
17
+ examples/openai/embeddings_create.py,sha256=XUY-CsXXLNJe6Hsdh2P5w03PomfZSWuy4QlL_yHHgKg,403
18
+ examples/openai/function_calling.py,sha256=BAuw0BAglWodZg9UrhdHsSkpwOEKdiV3zv13J1Bhsmk,2422
19
+ examples/openai/images_generate.py,sha256=5A-jEQcOOW2Z8SJNRv0MiRP5tJOOmMrfMg_78L8mxqQ,390
20
+ examples/pinecone_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ examples/pinecone_example/basic.py,sha256=g8hd_P662SAQKuJv8M7_XHtl9b7qd8Vlc55xFupX2U4,739
22
+ extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ extensions/langtrace_exporter.py,sha256=Sd58QwQqGIV4ip3-0D2nzhtB-zbPCCqlE7SR65s3qvE,2115
24
+ init/__init__.py,sha256=tsnStHYS-UYMniJRWmVslRuhbT01MAldx_nU4AZ2Ko0,26
25
+ init/init.py,sha256=Kkfn5e4H8m6yc6Bso8mRNv_IDmfhU5CKb1CvNp0_50k,2614
26
+ instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
+ instrumentation/chroma/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ instrumentation/chroma/apis.py,sha256=hiPGYdHS0Yj4Kh3eaYBbuCAl_swqIygu80yFqkOgdak,955
29
+ instrumentation/chroma/instrumentation.py,sha256=YlsyhlRoCYTgCRUvRCmZlxTtEcUQMj35r8-y6u6UX3M,1179
30
+ instrumentation/chroma/patch.py,sha256=TCxTS7sWDmS6Vi2IDS5ZVV4YW-zZh54nqQh6akq-KPo,1955
31
+ instrumentation/langchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
+ instrumentation/langchain/instrumentation.py,sha256=LXtx5edfHPLRZ9yP0yKbDHlvE7LOJumJMGTqQX5RhhM,2850
33
+ instrumentation/langchain/patch.py,sha256=CtDS-snAKL61XImh9MEN3QQ5XNruic2yN5YaCHtgEUQ,2986
34
+ instrumentation/langchain_community/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ instrumentation/langchain_community/instrumentation.py,sha256=XWzaHl4FPPlZEhnUlxRB0iO5kPkNVI9siRXZgxF_Yb4,4316
36
+ instrumentation/langchain_community/patch.py,sha256=0nqP0uTtpogYsu4-0fMRAdToKyCpVfl3n21GGuJ6L-o,2880
37
+ instrumentation/langchain_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
+ instrumentation/langchain_core/instrumentation.py,sha256=AYHqyuOwunuMqrTCxzXCbkIDmJbHA6Q40moHntdL4tw,4739
39
+ instrumentation/langchain_core/patch.py,sha256=YQbxlNUJA7XvQDHpVo3Snfpiq1Gen8x92Vs1NmkkuPg,7544
40
+ instrumentation/llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
+ instrumentation/llamaindex/instrumentation.py,sha256=WwETor8jLwaDQwnwgbtKZHQ3MwtNIfZSp1aaUn-uLIk,2759
42
+ instrumentation/llamaindex/patch.py,sha256=bcCfjBrBS9sSpge1m3se6NPqsHlw7K0jW-84gGdT6QE,1717
43
+ instrumentation/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
+ instrumentation/openai/instrumentation.py,sha256=Mkk6fwvQ8kS9ykFFc8OffIGbNMYVi6rrBVjVVhjuTjo,1408
45
+ instrumentation/openai/patch.py,sha256=9ch4tcl2fp_EF2bNAOZ8DV4r8VNeSxyV-5YPRDecMsE,12252
46
+ instrumentation/openai/token_estimation.py,sha256=j_JdAZNbAbpLdhSMdVIG5GvGwoIj2ZCC3LRrVTr7Tsg,1544
47
+ instrumentation/pinecone/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
+ instrumentation/pinecone/instrumentation.py,sha256=I0721lQFARpU9EfQ9eI-Yum80c8wQ48dp8tqLQ4ybGI,1713
49
+ instrumentation/pinecone/patch.py,sha256=TbTQ_eKkoeowyVtEwNYQRervqvVFCjvOeARmNDYXmxE,1852
50
+ utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
+ utils/with_root_span.py,sha256=CRie2ljHhnHN8bUGDwBM-F18-c6xyoI_238KP8BEO-U,969
52
+ langtrace_python_sdk-1.0.12.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
53
+ langtrace_python_sdk-1.0.12.dist-info/METADATA,sha256=SIzpMfuoAPWmyAiMKKm1kS1cq6wKFx73B_xGVFEeZgI,6245
54
+ langtrace_python_sdk-1.0.12.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
55
+ langtrace_python_sdk-1.0.12.dist-info/top_level.txt,sha256=oHxTmC4OfJqafm6-frLkJHxcBTTgetWc8lvVt-T_IMs,57
56
+ langtrace_python_sdk-1.0.12.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ constants
2
+ examples
3
+ extensions
4
+ init
5
+ instrumentation
6
+ utils
utils/__init__.py ADDED
File without changes
examples/setup.py DELETED
@@ -1,50 +0,0 @@
1
-
2
- from opentelemetry import trace
3
- from opentelemetry.sdk.trace import TracerProvider
4
- from opentelemetry.sdk.trace.export import (ConsoleSpanExporter,
5
- SimpleSpanProcessor)
6
-
7
- from instrumentation.chroma.instrumentation import ChromaInstrumentation
8
- from instrumentation.langchain.instrumentation import LangchainInstrumentation
9
- from instrumentation.langchain_community.instrumentation import \
10
- LangchainCommunityInstrumentation
11
- from instrumentation.langchain_core.instrumentation import \
12
- LangchainCoreInstrumentation
13
- from instrumentation.llamaindex.instrumentation import \
14
- LlamaindexInstrumentation
15
- from instrumentation.openai.instrumentation import OpenAIInstrumentation
16
- from instrumentation.pinecone.instrumentation import PineconeInstrumentation
17
-
18
-
19
- def setup_instrumentation():
20
-
21
- # Set up OpenTelemetry tracing
22
- tracer_provider = TracerProvider()
23
-
24
- # Use the ConsoleSpanExporter to print traces to the console
25
- console_exporter = ConsoleSpanExporter()
26
- tracer_provider.add_span_processor(SimpleSpanProcessor(console_exporter))
27
-
28
- # Initialize tracer
29
- trace.set_tracer_provider(tracer_provider)
30
-
31
- # Initialize and enable your custom OpenAI instrumentation
32
- # Create an instance of OpenAIInstrumentation
33
- openai_instrumentation = OpenAIInstrumentation()
34
- pinecone_instrumentation = PineconeInstrumentation()
35
- llamaindex_instrumentation = LlamaindexInstrumentation()
36
- chroma_instrumentation = ChromaInstrumentation()
37
- langchain_instrumentation = LangchainInstrumentation()
38
- langchain_core_instrumentation = LangchainCoreInstrumentation()
39
- langchain_community_instrumentation = LangchainCommunityInstrumentation()
40
-
41
- # Call the instrument method with some arguments
42
- openai_instrumentation.instrument()
43
- pinecone_instrumentation.instrument()
44
- llamaindex_instrumentation.instrument()
45
- chroma_instrumentation.instrument()
46
- langchain_instrumentation.instrument()
47
- langchain_core_instrumentation.instrument()
48
- langchain_community_instrumentation.instrument()
49
-
50
- print("setup complete")
@@ -1,19 +0,0 @@
1
- """
2
- APIs to instrument OpenAI.
3
- """
4
- from langtrace.trace_attributes import OpenAIMethods
5
-
6
- APIS = {
7
- "CHAT_COMPLETION": {
8
- "METHOD": OpenAIMethods.CHAT_COMPLETION.value,
9
- "ENDPOINT": "/chat/completions",
10
- },
11
- "IMAGES_GENERATION": {
12
- "METHOD": OpenAIMethods.IMAGES_GENERATION.value,
13
- "ENDPOINT": "/images/generations",
14
- },
15
- "EMBEDDINGS_CREATE": {
16
- "METHOD": OpenAIMethods.EMBEDDINGS_CREATE.value,
17
- "ENDPOINT": "/embeddings",
18
- },
19
- }
@@ -1,53 +0,0 @@
1
- examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- examples/setup.py,sha256=07Sy36lUuNuPU5QPAs2BEMm-YKSosruzKJPl0QKc_rc,2105
3
- examples/chroma_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- examples/chroma_example/basic.py,sha256=HD8vGSsvcXN21AuWyUx09CePphXrIp9PSNllueMqvEI,836
5
- examples/langchain_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- examples/langchain_example/basic.py,sha256=PBYotFDJlkH9y17U8WRbH3FxqgfBPHra2k_C7hHPiMc,1993
7
- examples/langchain_example/tool.py,sha256=g7mFuXal6TtCvo-KTYqWeSEpuyQMR2LuHF6WQdKRwbw,2494
8
- examples/llamaindex_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- examples/llamaindex_example/basic.py,sha256=b1y1VnYE7eaeSXLk9rJ4EZApCj-tMPPMTY-fc_M7X7c,620
10
- examples/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- examples/openai/chat_completion.py,sha256=3ojkccgntJp_IXnNb7f7w9sXPtj_mDNOE7IyLB6SsS0,1300
12
- examples/openai/embeddings_create.py,sha256=01ApMJ2F_8-IWanDAD8SWlrcjg8b3mJzaddsGhRvrck,457
13
- examples/openai/function_calling.py,sha256=MzxNNvPNdUWOw8Ugs_gMGuwyQN4yPJnja46rE_8W_ZY,2475
14
- examples/openai/images_generate.py,sha256=GD2Bj902xqS0pfZr0pZtPXCGHEHWZM_CjGJ0DdoP_pY,444
15
- examples/pinecone_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- examples/pinecone_example/basic.py,sha256=lF8TcDvW1v6j-QKvl3B9r1t0ShnvCcOgJ5F74qy6VO8,793
17
- instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- instrumentation/constants.py,sha256=YdC62dsYpbbBdMHhfUbaK-cbDM4w4eau0ClUdWVmjmU,336
19
- instrumentation/with_root_span.py,sha256=CRie2ljHhnHN8bUGDwBM-F18-c6xyoI_238KP8BEO-U,969
20
- instrumentation/chroma/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- instrumentation/chroma/apis.py,sha256=hiPGYdHS0Yj4Kh3eaYBbuCAl_swqIygu80yFqkOgdak,955
22
- instrumentation/chroma/instrumentation.py,sha256=ySEyLnXcjL7D3sgMHTkxwdpxDpsRVbRJvFOgTxYRHvs,1174
23
- instrumentation/chroma/patch.py,sha256=2ERORLV4_F1UU2Is8Y4H7aEXNnAPI5XKvW9DnLeEndM,1943
24
- instrumentation/chroma/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- instrumentation/langchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- instrumentation/langchain/instrumentation.py,sha256=LXtx5edfHPLRZ9yP0yKbDHlvE7LOJumJMGTqQX5RhhM,2850
27
- instrumentation/langchain/patch.py,sha256=f-lq0wdk7doop-Dak2VcGueDsESA_5RKyuGtJQIm4DQ,2979
28
- instrumentation/langchain_community/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- instrumentation/langchain_community/instrumentation.py,sha256=XWzaHl4FPPlZEhnUlxRB0iO5kPkNVI9siRXZgxF_Yb4,4316
30
- instrumentation/langchain_community/patch.py,sha256=w6R_lHTDg2GzWRH8BZNocQowedeaNUE-pLfCoRETnTk,2872
31
- instrumentation/langchain_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
- instrumentation/langchain_core/instrumentation.py,sha256=AYHqyuOwunuMqrTCxzXCbkIDmJbHA6Q40moHntdL4tw,4739
33
- instrumentation/langchain_core/patch.py,sha256=a314C0IaF0gSa2eh-yO8jHqtZwnWIczQsF3FgCgoiiU,7536
34
- instrumentation/llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
- instrumentation/llamaindex/instrumentation.py,sha256=WwETor8jLwaDQwnwgbtKZHQ3MwtNIfZSp1aaUn-uLIk,2759
36
- instrumentation/llamaindex/patch.py,sha256=hSSoOij70kIhAleHLOfTW-zNc-N9boQz1iyhoBdVRsQ,1709
37
- instrumentation/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
- instrumentation/openai/apis.py,sha256=lMUa6rCkT-fKltngOUxcXd0aNpTb5L8xlqjrdseLIZM,488
39
- instrumentation/openai/constants.py,sha256=3_xaFfAhh2dpH0072Cijzb5iZazUpmj4SF0iWiMFm1A,973
40
- instrumentation/openai/instrumentation.py,sha256=Mkk6fwvQ8kS9ykFFc8OffIGbNMYVi6rrBVjVVhjuTjo,1408
41
- instrumentation/openai/patch.py,sha256=Syktbjz9R-XjGj9QEGojZ4fsxZdQ7Gq4nPOW49J4fLA,12234
42
- instrumentation/openai/token_estimation.py,sha256=nwTR0yyZs2OB0S3bBviBgd_xMb6oh7nCPMt-HlIlCRU,1549
43
- instrumentation/openai/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
- instrumentation/pinecone/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
- instrumentation/pinecone/apis.py,sha256=XpKNUfyzEE3HkBN10Qv1w_t1PT-J39pHlotrdU-wvec,477
46
- instrumentation/pinecone/instrumentation.py,sha256=yfOxKkMtW6GEUQ0E9AWSBdaa07MHzV3o6Q09cAvoWIU,1708
47
- instrumentation/pinecone/patch.py,sha256=fr07o97CqGc8sUEyMtSiT6watZiTPStRPOrxOzhJGLo,1840
48
- instrumentation/pinecone/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- langtrace_python_sdk-1.0.11.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
50
- langtrace_python_sdk-1.0.11.dist-info/METADATA,sha256=Zgg1c6Ykg62bBICe3rPmogg4GWjTe-WwtnGWQyVJ_mA,6149
51
- langtrace_python_sdk-1.0.11.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
52
- langtrace_python_sdk-1.0.11.dist-info/top_level.txt,sha256=FJhLokAk3p9qB-lzJKTfQ1CtAXoxvyL8zkfffVrFSdI,25
53
- langtrace_python_sdk-1.0.11.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- examples
2
- instrumentation
File without changes
File without changes
File without changes