Skip to content

Commit 2b1e66f

Browse files
committed
refactored to fit Johnny's PR
1 parent 7a8c2dd commit 2b1e66f

File tree

12 files changed

+25
-11
lines changed

12 files changed

+25
-11
lines changed

aws-opentelemetry-distro/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ test = []
9595
[project.entry-points.opentelemetry_configurator]
9696
aws_configurator = "amazon.opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenTelemetryConfigurator"
9797

98+
[project.entry-points.opentelemetry_instrumentor]
99+
langchain = "amazon.opentelemetry.distro.instrumentation.mcp.instrumentation:McpInstrumentor"
100+
98101
[project.entry-points.opentelemetry_distro]
99102
aws_distro = "amazon.opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"
100103

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
from wrapt import wrap_function_wrapper
99

10+
from amazon.opentelemetry.distro.opentelemetry.instrumentation.langchain_v2.callback_handler import (
11+
OpenTelemetryCallbackHandler,
12+
)
13+
from amazon.opentelemetry.distro.opentelemetry.instrumentation.langchain_v2.version import __version__
1014
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
11-
from opentelemetry.instrumentation.langchain_v2.callback_handler import OpenTelemetryCallbackHandler
12-
from opentelemetry.instrumentation.langchain_v2.version import __version__
1315
from opentelemetry.instrumentation.utils import unwrap
1416
from opentelemetry.trace import get_tracer
1517

@@ -20,7 +22,7 @@
2022

2123
class LangChainInstrumentor(BaseInstrumentor):
2224

23-
def instrumentation_dependencies(self, cls) -> Collection[str]:
25+
def instrumentation_dependencies(self) -> Collection[str]:
2426
return _instruments
2527

2628
def _instrument(self, **kwargs):
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
from langchain_core.messages import BaseMessage
1414
from langchain_core.outputs import LLMResult
1515

16+
from amazon.opentelemetry.distro.opentelemetry.instrumentation.langchain_v2.span_attributes import (
17+
GenAIOperationValues,
18+
SpanAttributes,
19+
)
1620
from opentelemetry import context as context_api
17-
from opentelemetry.instrumentation.langchain_v2.span_attributes import GenAIOperationValues, SpanAttributes
1821
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
1922
from opentelemetry.trace import SpanKind, set_span_in_context
2023
from opentelemetry.trace.span import Span

ai_agent_instrumentation/opentelemetry-instrumentation-langchain-v2/pyproject.toml renamed to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/opentelemetry/instrumentation/langchain_v2/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ instruments = [
3737

3838

3939
[tool.hatch.version]
40-
path = "src/opentelemetry/instrumentation/langchain_v2/version.py"
40+
path = "version.py"
41+
4142

4243
[tool.hatch.build.targets.sdist]
4344
include = [

ai_agent_instrumentation/opentelemetry-instrumentation-langchain-v2/tests/conftest.py renamed to aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test-opentelemetry-instrumentation-langchain-v2/conftest.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import os
77

88
import pytest
9-
from src.opentelemetry.instrumentation.langchain_v2 import LangChainInstrumentor
109

10+
from amazon.opentelemetry.distro.opentelemetry.instrumentation.langchain_v2 import LangChainInstrumentor
1111
from opentelemetry.sdk._logs.export import InMemoryLogExporter
1212
from opentelemetry.sdk.trace import TracerProvider
1313
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
@@ -97,15 +97,19 @@ def instrument_with_content(tracer_provider):
9797
instrumentor.uninstrument()
9898

9999

100+
# Define these variables once at the module level
101+
current_dir = os.path.dirname(os.path.abspath(__file__))
102+
cassette_dir = os.path.join(current_dir, "fixtures", "vcr_cassettes")
103+
# Create the directory for cassettes if it doesn't exist
104+
os.makedirs(cassette_dir, exist_ok=True)
105+
106+
100107
@pytest.fixture(scope="module")
101108
def vcr_config():
109+
# Reuse the module-level variables instead of redefining them
102110
return {
103111
"filter_headers": ["Authorization", "X-Amz-Date", "X-Amz-Security-Token"],
104112
"filter_query_parameters": ["X-Amz-Signature", "X-Amz-Credential", "X-Amz-SignedHeaders"],
105113
"record_mode": "once",
106-
"cassette_library_dir": "tests/fixtures/vcr_cassettes",
114+
"cassette_library_dir": cassette_dir,
107115
}
108-
109-
110-
# Create the directory for cassettes if it doesn't exist
111-
os.makedirs("tests/fixtures/vcr_cassettes", exist_ok=True)

0 commit comments

Comments
 (0)