Skip to content

feat: added Langchain mappers#153

Merged
poshinchen merged 1 commit intostrands-agents:mainfrom
poshinchen:feat/add-base-mapper-and-langchain-mapper
Mar 13, 2026
Merged

feat: added Langchain mappers#153
poshinchen merged 1 commit intostrands-agents:mainfrom
poshinchen:feat/add-base-mapper-and-langchain-mapper

Conversation

@poshinchen
Copy link
Copy Markdown
Contributor

@poshinchen poshinchen commented Mar 9, 2026

Description

This PR adds a mapper framework for converting OpenTelemetry traces from different LangChain (with traceloop / openllmetry) into a unified Session format for evaluation

Architecture

Base Class:

  • SessionMapper (abstract base class) - defines the map_to_session(data, session_id) interface and provides _normalize_to_flat_spans() helper for handling various input formats

Famework-Specific Mappers:

  1. LangChainOtelSessionMapper: Maps Traceloop/OpenLLMetry LangChain traces (scope: opentelemetry.instrumentation.langchain)

  2. OpenInferenceSessionMapper: Maps OpenInference LangChain traces (scope: openinference.instrumentation.langchain)

  3. CloudWatchSessionMapper: Maps Strands telemetry from CloudWatch/ADOT format

  4. StrandsInMemorySessionMapper: Maps Strands in-memory OTEL spans (existing, now inherits from base)

Utilities:

  • detect_otel_mapper(spans) - Auto-detects appropriate mapper based on scope name
  • readable_spans_to_dicts(spans) - Converts ReadableSpan objects to dict format
  • get_scope_name(span) - Extracts scope from various span formats
  • CloudWatchLogsParser - Normalizes raw CloudWatch logs to standard span format

Cleanup Opportunities for Follow-up

1. Extract Common Helper Methods to Base Class

The following methods are duplicated across all mappers:

  • _get_scope_name() - identical in LangChain & OpenInference mappers
  • _create_span_info() - nearly identical across all mappers
  • _parse_timestamp() - identical in LangChain & OpenInference mappers
  • _safe_json_parse() - identical logic (only in LangChain, but useful for others)

2. DRY Up Build Trace Logic

_build_trace() method has identical structure in LangChainOtelSessionMapper and OpenInferenceSessionMapper. This pattern could be moved to base class with abstract is*_span() methods.

3. Consolidate Message Extraction Pattern

_get_messages_from_span_events() has similar logic in both LangChain and OpenInference mappers for extracting messages from ADOT/CloudWatch format.

4. Unify Tool Extraction

_extract_tools_from_attributes() could be generalized - both mappers extract tool schemas but from different attribute keys.

Related Issues

#91

Documentation PR

N/A

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@poshinchen poshinchen force-pushed the feat/add-base-mapper-and-langchain-mapper branch from 715d093 to 8489766 Compare March 10, 2026 17:09
@poshinchen poshinchen changed the title (WIP) feat: added mappers for additional frameworks feat: added mappers for additional frameworks Mar 10, 2026
@poshinchen poshinchen changed the title feat: added mappers for additional frameworks feat: added Langchain mappers Mar 10, 2026
@afarntrog
Copy link
Copy Markdown
Contributor

I would also like to see integration tests that run with langchain agent so that we can know immediately if something changes as our tests will fail.

@poshinchen poshinchen force-pushed the feat/add-base-mapper-and-langchain-mapper branch from 8489766 to af53d71 Compare March 12, 2026 15:35
@poshinchen poshinchen force-pushed the feat/add-base-mapper-and-langchain-mapper branch from af53d71 to 4686de8 Compare March 12, 2026 15:52
@poshinchen poshinchen force-pushed the feat/add-base-mapper-and-langchain-mapper branch from 4686de8 to 845f372 Compare March 12, 2026 16:10
@poshinchen poshinchen merged commit 4080ba8 into strands-agents:main Mar 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants