-
Notifications
You must be signed in to change notification settings - Fork 40
chore: instana-otlp span mapper #2534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
abhilash-sivan
wants to merge
9
commits into
chore-otlp-playground
Choose a base branch
from
chore-otel-span-mapper
base: chore-otlp-playground
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
378f117
chore: phase 1
abhilash-sivan c1ef77d
chore: phase 2
abhilash-sivan d261bc5
chore: phase 3
abhilash-sivan 17710d0
chore: cleanup
abhilash-sivan 0a6ec17
chore: rewrite
abhilash-sivan 8a89eef
chore: test
abhilash-sivan c78331c
chore: a
abhilash-sivan bcb034e
chore: new fields
abhilash-sivan 980a1c0
chore: test
abhilash-sivan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
113 changes: 113 additions & 0 deletions
113
packages/core/src/tracing/backend_mappers/otlpMapper.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * (c) Copyright IBM Corp. 2026 | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * OTLP attribute mappings for different span types. | ||
| * Maps Instana span data fields to OTLP semantic convention attributes. | ||
| * | ||
| * Based on OpenTelemetry Semantic Conventions for HTTP: | ||
| * - Common HTTP exit (client) span mapping | ||
| * - Common HTTP entry (server) span mapping | ||
| * | ||
| * @type {Object<string, Object<string, string>>} | ||
| */ | ||
| const otlpAttributeMappings = { | ||
| http: { | ||
| // HTTP method mapping (both client and server) | ||
| // Instana: http.method -> OTel: http.request.method | ||
| method: 'http.request.method', | ||
|
|
||
| // HTTP status code mapping (both client and server) | ||
| // Instana: http.status -> OTel: http.response.status_code | ||
| status: 'http.response.status_code', | ||
|
|
||
| // HTTP URL mapping (client spans) | ||
| // Instana: http.url -> OTel: url.full | ||
| url: 'url.full', | ||
|
|
||
| // HTTP path mapping (server spans) | ||
| // Instana: http.path -> OTel: url.path | ||
| path: 'url.path', | ||
|
|
||
| // HTTP host mapping (both client and server) | ||
| // Instana: http.host -> OTel: server.address (simplified, may need port handling) | ||
| host: 'server.address', | ||
|
|
||
| // HTTP protocol mapping | ||
| // Instana: http.protocol -> OTel: network.protocol.name (may need version split) | ||
| protocol: 'network.protocol.name', | ||
|
|
||
| // HTTP query parameters mapping (both client and server) | ||
| // Instana: http.params -> OTel: url.query | ||
| params: 'url.query', | ||
|
|
||
| // HTTP path template mapping (both client and server) | ||
| // Instana: http.path_tpl -> OTel: url.template | ||
| path_tpl: 'url.template', | ||
|
|
||
| // HTTP error mapping (both client and server) | ||
| // Instana: http.error -> OTel: error.type | ||
| error: 'error.type', | ||
|
|
||
| // Note: http.context_root mapping is not included as it conflicts with http.path | ||
| // Both would map to url.path. Context root extraction requires special logic | ||
| // and should be implemented separately when needed. | ||
|
|
||
| // Legacy mappings for backward compatibility | ||
| status_text: 'http.status_text', | ||
|
|
||
| // HTTP route mapping (alternative to path_tpl) | ||
| route: 'http.route' | ||
| }, | ||
|
|
||
| // resource but added for ui view, without this .. ? | ||
| service: { | ||
| name: 'service.name' | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Transforms span data fields to OTLP attribute naming while keeping | ||
| * the mapper logic separate from the backend field mapping. | ||
| * | ||
| * @param {import('../../core').InstanaBaseSpan} span | ||
| * @returns {import('../../core').InstanaBaseSpan} The transformed span. | ||
| */ | ||
| module.exports.transform = span => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same transform logic, like we already do for instana internal format to backend compatible conversion |
||
| if (!span || !span.data) { | ||
| return span; | ||
| } | ||
|
|
||
| Object.keys(span.data).forEach(key => { | ||
| const mappings = otlpAttributeMappings[key]; | ||
| if (!mappings || typeof span.data[key] !== 'object' || span.data[key] === null) { | ||
| return; | ||
| } | ||
|
|
||
| applyMappings(span.data[key], mappings, key); | ||
| }); | ||
|
|
||
| return span; | ||
| }; | ||
|
|
||
| /** | ||
| * Applies OTLP field mappings to a specific data section. | ||
| * | ||
| * @param {Record<string, any>} dataSection | ||
| * @param {Object<string, string>} mappings | ||
| * @param {string} sectionKey | ||
| */ | ||
| function applyMappings(dataSection, mappings, sectionKey) { | ||
| Object.keys(dataSection).forEach(internalField => { | ||
| const mappedField = mappings[internalField] || `${sectionKey}.${internalField}`; | ||
| dataSection[mappedField] = dataSection[internalField]; | ||
| delete dataSection[internalField]; | ||
| }); | ||
| } | ||
|
|
||
| module.exports.getOtlpAttributeMappings = function () { | ||
| return otlpAttributeMappings; | ||
| }; | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing the conversion from spanBuffer