feat(observability): add InMemoryExporter and TLS timeout support#50
Open
wucm667 wants to merge 1 commit intovolcengine:mainfrom
Open
feat(observability): add InMemoryExporter and TLS timeout support#50wucm667 wants to merge 1 commit intovolcengine:mainfrom
wucm667 wants to merge 1 commit intovolcengine:mainfrom
Conversation
- Add InMemoryExporter for in-memory span collection with session tracking: - ExportSpans stores spans with trace ID and session-to-trace mapping - GetSpans / GetSpansBySession for retrieval - Reset / Shutdown to clear state - ForceFlush as no-op - Dump method to export spans as JSON file (by session or all) - Add configurable TLS exporter timeout: - New TLSExporterConfig.Timeout field (seconds, default 10s) - New env var OBSERVABILITY_OPENTELEMETRY_TLS_TIMEOUT - Apply timeout to both trace and metric TLS exporters via otlptracehttp/otlpmetrichttp options - Add TLS metric export support in NewMetricReader - Refactor: rename sdk/trace import alias to sdktrace for clarity - Add comprehensive unit tests for InMemoryExporter
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the
observabilitymodule with the following improvements:Timeoutfield toTLSExporterConfig, giving users control over the OTLP HTTP request timeout for both trace and metric TLS exporters.NewMetricReader: Automatically registers a TLS periodic metric reader when TLS credentials are configured.sdk/traceandotel/tracepackage imports by aliasing the former assdktrace.Changed Files
configs/observability.goTLSExporterConfig.Timeoutfield and corresponding env varobservability/exporter.goInMemoryExporter, TLS timeout logic, TLS metric reader registrationobservability/exporter_test.goInMemoryExporterDetails
1. InMemoryExporter
InMemoryExporterimplements thesdktrace.SpanExporterinterface and stores spans in memory. It is designed for testing and local debugging scenarios where a real OTLP backend is not available.Features:
ExportSpansappends spans to an internal slice and tracks the currentTraceID.call_llmspans for thegen_ai.session.idattribute and maintains a session → traceID mapping.GetSpansBySession(sessionID)returns all spans belonging to the given session.GetSpans()returns all collected spans.Reset()/Shutdown()clear all spans and session mappings.Dump(sessionID, dir)serializes spans to a JSON file. File naming convention:veadk_trace_{sessionID}_{traceID}.jsonveadk_trace_{traceID}.jsonUsage example:
2. Configurable TLS Exporter Timeout
New config field:
Environment variable:
Behavior:
Timeout <= 0, the default of10s(defaultTLSTimeout) is used.NewTLSExporter) and the metric exporter (NewTLSMetricExporter) viaotlptracehttp.WithTimeout/otlpmetrichttp.WithTimeout.createTraceClient/createMetricClientwrappers are bypassed for TLS exporters to allow direct option composition.Helper function:
3. TLS Metric Export in NewMetricReader
NewMetricReadernow automatically registers a TLS periodic metric reader when TLS credentials are present:Previously, TLS metric export was not automatically registered even when TLS credentials were configured. This change brings metric export behavior in line with trace export.
4. Import Alias Refactor
The
go.opentelemetry.io/otel/sdk/tracepackage is now imported assdktraceto disambiguate it fromgo.opentelemetry.io/otel/trace. The following function signatures are updated accordingly:NewStdoutExporter() (sdktrace.SpanExporter, error)NewCozeLoopExporter(...) (sdktrace.SpanExporter, error)NewAPMPlusExporter(...) (sdktrace.SpanExporter, error)NewTLSExporter(...) (sdktrace.SpanExporter, error)NewFileExporter(...) (sdktrace.SpanExporter, error)NewMultiExporter(...) (sdktrace.SpanExporter, error)multiExporter.ExportSpans(ctx, []sdktrace.ReadOnlySpan)Tests
Added
TestInMemoryExportertest suite covering:new exporter is emptyexport and retrieve spanssession trackinggen_ai.session.idattribute oncall_llmspans is mapped to sessionreset clears all dataReset()clears spans and session mappingsshutdown clears all dataShutdown()clears all stateforce flush is no-opForceFlush()returns no errordump to filedump all spans when session is emptyConfiguration Reference
Full TLS exporter configuration example (
config.yaml):Or via environment variables: