Add OpenTelemetry (OTLP/HTTP) receiver for AI coding assistant telemetry#17516
Open
JackieTien97 wants to merge 1 commit intomasterfrom
Open
Add OpenTelemetry (OTLP/HTTP) receiver for AI coding assistant telemetry#17516JackieTien97 wants to merge 1 commit intomasterfrom
JackieTien97 wants to merge 1 commit intomasterfrom
Conversation
…ding assistant telemetry
Add an OTLP/HTTP receiver to IoTDB's REST service that accepts
OpenTelemetry traces, metrics, and logs via standard OTLP/HTTP
endpoints. This enables storing telemetry data from AI coding
assistants (Claude Code, Codex, Gemini CLI, etc.) directly into
IoTDB's table model for local analytics.
Key design decisions:
- Reuses the existing REST service (Jetty + Jersey) on port 18080
rather than introducing a new server or gRPC dependency
- Database name is derived dynamically from each request's
service.name resource attribute (e.g. claude-code -> claude_code,
codex -> codex), so different tools land in separate databases
- OTLP attributes are flattened into typed TAG/ATTRIBUTE/FIELD
columns instead of being stored as opaque JSON blobs, enabling
efficient time-series queries without JSON parsing
- Schema (database + tables) is created automatically on first
ingest via idempotent DDL
New files (external-service-impl/rest/.../protocol/otlp/v1/):
- OtlpTracesResource/MetricsResource/LogsResource: JAX-RS endpoints
at /rest/v1/otlp/v1/{traces,metrics,logs}
- OtlpService: singleton managing per-database sessions and schema
- OtlpSchemaInitializer: idempotent CREATE DATABASE/TABLE DDL
- OtlpIngestor + OtlpTableBatch: column-major batch -> InsertTablet
- OtlpTracesConverter/MetricsConverter/LogsConverter: OTLP -> rows
- OtlpConverter: timestamp precision, hex encoding, attribute helpers
- OtlpHttp: protobuf/JSON request parsing and response rendering
Modified files:
- rest/pom.xml: added opentelemetry-proto + protobuf-java-util deps
- AuthorizationFilter: bypass auth for /rest/v1/otlp/ paths
- IoTDBRestServiceConfig/Descriptor: added otlp_username/password
- iotdb-system.properties.template: documented OTLP config section
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #17516 +/- ##
============================================
- Coverage 39.87% 39.86% -0.01%
Complexity 312 312
============================================
Files 5137 5137
Lines 347150 347160 +10
Branches 44247 44247
============================================
- Hits 138420 138403 -17
- Misses 208730 208757 +27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 adds an OTLP/HTTP receiver to IoTDB's REST service, enabling IoTDB to directly ingest OpenTelemetry telemetry data (traces, metrics, and logs) from AI coding assistants such as Claude Code, Codex, Gemini CLI, and others.
Motivation
Modern AI coding assistants like Claude Code emit rich telemetry data via the OpenTelemetry protocol — including token usage, API costs, tool execution stats, and session events. Storing this data locally in IoTDB enables developers and teams to:
prompt.idHow It Works
The OTLP receiver is embedded in the existing REST service (port 18080) and exposes three standard OTLP/HTTP endpoints:
Both
application/x-protobufandapplication/jsoncontent types are supported.Dynamic database routing: The receiver derives the target database name from each request's
service.nameresource attribute. For example:claude-code→ databaseclaude_codecodex→ databasecodexGemini CLI→ databasegemini_cliDatabase and tables (
metrics,logs,traces) are created automatically on first use.Table Schema Design (Table Model)
metricstable — one row per data point, with OTLP attributes extracted into typed columns:user_idsession_idmetric_nameclaude_code.token.usage,claude_code.cost.usagemodelclaude-opus-4-7typeinput/output/cacheRead/cacheCreation/user/cliterminal_typeiTerm.app/vscode/cursorservice_versionos_type,os_version,host_archunit,metric_type,descriptionvaluelogstable — flattened event records with event-type-specific columns:user_id,session_idevent_nameuser_prompt/api_request/api_error/tool_result/tool_decisionterminal_type,service_version,os_type,host_archprompt_id,event_sequence,bodymodel,cost_usd,duration_ms,input_tokens,output_tokens, ...tool_name,success,tool_duration_ms,decision,decision_sourcetracestable — standard span data with resource attributes extracted.How to Use with Claude Code
Enable REST service in
iotdb-system.properties:Add the following environment variables to your shell profile (e.g.
~/.zshrcor~/.bashrc):Start IoTDB, then start a new Claude Code session. Telemetry data will flow automatically.
Query your data:
Files Changed
New files (11 files in
external-service-impl/rest/.../protocol/otlp/v1/):OtlpTracesResource,OtlpMetricsResource,OtlpLogsResource— JAX-RS endpointsOtlpService— per-database session management + schema initOtlpSchemaInitializer— idempotentCREATE DATABASE/TABLE IF NOT EXISTSOtlpIngestor+OtlpTableBatch— column-major batch →InsertTabletStatementOtlpTracesConverter,OtlpMetricsConverter,OtlpLogsConverter— OTLP→rowsOtlpConverter— timestamp precision, hex encoding, attribute extractionOtlpHttp— protobuf/JSON parsing and response renderingModified files (5 files):
rest/pom.xml— addedio.opentelemetry.proto:opentelemetry-proto+protobuf-java-utilAuthorizationFilter— bypass auth for/rest/v1/otlp/paths (OTLP receiver authenticates internally viaotlp_username/otlp_password)IoTDBRestServiceConfig/Descriptor— addedotlp_username/otlp_passwordconfigiotdb-system.properties.template— documented OTLP configuration sectionTest plan
mvn clean package -pl distribution -am -DskipTestssucceedscurl -X POST http://localhost:18080/rest/v1/otlp/v1/logswith JSON body returns HTTP 200claude_code.metrics🤖 Generated with Claude Code