- 
                Notifications
    You must be signed in to change notification settings 
- Fork 351
Add support for OpenTelemetry Logs API #6465
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 13 commits
      Commits
    
    
            Show all changes
          
          
            66 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      343c772
              
                first attempt at otel logs support
              
              
                mabdinur b3a2973
              
                lint files and centralize configs
              
              
                mabdinur 2c0d528
              
                add tests
              
              
                mabdinur 6c359ce
              
                clean up yarn.lock
              
              
                mabdinur 7dc1480
              
                clean up logs
              
              
                mabdinur 2c60dfc
              
                add back log exporter logic
              
              
                mabdinur dabe98f
              
                clean up docs
              
              
                mabdinur b7ae33d
              
                clean up docs and fix otlp protocol
              
              
                mabdinur f73d425
              
                revert readme docs
              
              
                mabdinur 543805a
              
                add new otel files
              
              
                mabdinur c63e20e
              
                working version
              
              
                mabdinur d4d8aac
              
                fmy
              
              
                mabdinur 9514e68
              
                fmt
              
              
                mabdinur df7cbca
              
                Update packages/dd-trace/src/config_defaults.js
              
              
                mabdinur 2c0a5a5
              
                fix tests
              
              
                mabdinur f109cf3
              
                allow any version of logs api, let opentelemetry api determine the ve…
              
              
                mabdinur 0c29478
              
                add otlp payload tests
              
              
                mabdinur 8b1ce46
              
                add telemetry metrics
              
              
                mabdinur 432ec89
              
                some other clean ups
              
              
                mabdinur 036776a
              
                simplify tests
              
              
                mabdinur 8abbe95
              
                use agent hostname to resolve otlp endpoints
              
              
                mabdinur e9456e3
              
                clean up initalization
              
              
                mabdinur 9164c6f
              
                Merge branch 'master' into munir/otlp-logs-support
              
              
                mabdinur 4bc66fc
              
                parse additional otlp headers
              
              
                mabdinur d505cab
              
                clean up component args
              
              
                mabdinur 0f2bd21
              
                clean up docs
              
              
                mabdinur 3af5080
              
                clean up component args
              
              
                mabdinur 9578887
              
                remove addLogProcessor, init provider with a processor
              
              
                mabdinur c7c15d8
              
                support trace-log correlation
              
              
                mabdinur f6f58fe
              
                clean up registering provider in tests, and rename exporter arg
              
              
                mabdinur 434fbc4
              
                first round of clean ups from PR review
              
              
                mabdinur 3963ed6
              
                clean ups part 2
              
              
                mabdinur 6d10314
              
                make things private and clean up tests
              
              
                mabdinur 11161f3
              
                clean up tests
              
              
                mabdinur 266c936
              
                clean up yarn file
              
              
                mabdinur d63a4ed
              
                remove unused configs
              
              
                mabdinur b98cd76
              
                fix context issues
              
              
                mabdinur 9955d5e
              
                nother round of clean ups
              
              
                mabdinur a9ddbcc
              
                group payloads by instrumentation scope
              
              
                mabdinur d9d9dfb
              
                fix typing
              
              
                mabdinur 351ca2f
              
                address review comments
              
              
                mabdinur b99ba1d
              
                add better typing, and better support for sending schemaurl
              
              
                mabdinur 07ec605
              
                Merge branch 'master' into munir/otlp-logs-support
              
              
                mabdinur a1f8cf7
              
                revert instrumentationScope change to span
              
              
                mabdinur 09fedbc
              
                Merge branch 'master' into munir/otlp-logs-support
              
              
                mabdinur 9ff13fd
              
                review comments
              
              
                mabdinur 0b8e71d
              
                clean up protobuf loader file
              
              
                mabdinur 46d1385
              
                Merge branch 'master' into munir/otlp-logs-support
              
              
                mabdinur 5410486
              
                lint
              
              
                mabdinur 55e86e9
              
                move protos to same dir, this will set up metrics work
              
              
                mabdinur 311500c
              
                clean up throws
              
              
                mabdinur 07ab61c
              
                update protos
              
              
                mabdinur f25c7a5
              
                disable log injection when otel logs support is enabled
              
              
                mabdinur 9f716d1
              
                update configurations to pass telemetry system tests
              
              
                mabdinur ea532c2
              
                remove useless import
              
              
                mabdinur e695249
              
                add more tests
              
              
                mabdinur 557b6d5
              
                provide fix for failing system test
              
              
                mabdinur 266a239
              
                add test case for noop logger and fix mocking for remote config
              
              
                mabdinur df5d6b4
              
                add test case for noop logger and fix mocking for remote config
              
              
                mabdinur 2763296
              
                Merge branch 'master' into munir/otlp-logs-support
              
              
                mabdinur e995e0c
              
                fix encoding for doubles, remove unused shutdown code, test getLogger…
              
              
                mabdinur e20668e
              
                remove unused timer and shutdown logic, simplify loggerprovider regis…
              
              
                mabdinur 3f8eab1
              
                fix comment
              
              
                mabdinur 148d47b
              
                clean up how otel endpoint configs are loaded
              
              
                mabdinur 9ac86bb
              
                address Ayans comments
              
              
                mabdinur 7f4fbff
              
                add integration tests
              
              
                mabdinur 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
          Some comments aren't visible on the classic Files Changed page.
        
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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
        
          
  
    
      
          
            138 changes: 138 additions & 0 deletions
          
          138 
        
  packages/dd-trace/src/opentelemetry/logs/batch_log_processor.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,138 @@ | ||
| 'use strict' | ||
|  | ||
| /** | ||
| * @fileoverview BatchLogRecordProcessor implementation for OpenTelemetry logs | ||
| * | ||
| * Custom implementation to avoid pulling in the full OpenTelemetry SDK. | ||
| * Based on OTLP Protocol v1.7.0. | ||
| */ | ||
|  | ||
| const log = require('../../log') | ||
|  | ||
| /** | ||
| * BatchLogRecordProcessor processes log records in batches for efficient export. | ||
| * | ||
| * This implementation follows the OpenTelemetry JavaScript SDK BatchLogRecordProcessor: | ||
| * https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_sdk-logs.BatchLogRecordProcessor.html | ||
|         
                  mabdinur marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| * | ||
| * @class BatchLogRecordProcessor | ||
| */ | ||
| class BatchLogRecordProcessor { | ||
| /** | ||
| * Creates a new BatchLogRecordProcessor instance. | ||
| * | ||
| * @param {Array} processors - Array of log processors to process batches | ||
| * @param {Object} config - Configuration options | ||
| * @param {number} [config.batchTimeout=5000] - Timeout in milliseconds for batch processing | ||
| * @param {number} [config.maxExportBatchSize=512] - Maximum number of log records per batch | ||
| * @param {number} [config.maxQueueSize=2048] - Maximum number of log records in queue | ||
| * @param {number} [config.exportTimeoutMillis=30000] - Timeout for export operations | ||
| */ | ||
| constructor (processors, config) { | ||
| this._processors = processors | ||
| this._config = config | ||
| this._isShutdown = false | ||
| this._batchTimeout = config.batchTimeout || 5000 // 5 seconds default | ||
| this._maxExportBatchSize = config.maxExportBatchSize || 512 | ||
| this._maxQueueSize = config.maxQueueSize || 2048 | ||
| this._exportTimeoutMillis = config.exportTimeoutMillis || 30_000 // 30 seconds default | ||
|  | ||
| this._logRecords = [] | ||
| this._timer = null | ||
| this._shutdownPromise = null | ||
| } | ||
|  | ||
| /** | ||
| * Processes a single log record. | ||
| * | ||
| * @param {Object} logRecord - The log record to process | ||
| */ | ||
| onEmit (logRecord) { | ||
| if (this._isShutdown) { | ||
| return | ||
| } | ||
|  | ||
| this._logRecords.push(logRecord) | ||
|  | ||
| if (this._logRecords.length >= this._maxExportBatchSize) { | ||
| this._export() | ||
| } else if (this._logRecords.length === 1) { | ||
| this._startTimer() | ||
| } | ||
| } | ||
|  | ||
| _startTimer () { | ||
| if (this._timer) { | ||
| return | ||
| } | ||
|  | ||
| this._timer = setTimeout(() => { | ||
| this._export() | ||
| }, this._batchTimeout) | ||
| } | ||
|  | ||
| _export () { | ||
| if (this._logRecords.length === 0) { | ||
| return | ||
| } | ||
|  | ||
| const logRecords = this._logRecords.splice(0, this._maxExportBatchSize) | ||
| this._clearTimer() | ||
|  | ||
| for (const processor of this._processors) { | ||
| try { | ||
| processor.export(logRecords, () => {}) | ||
| } catch (error) { | ||
| log.error('Error in log processor export:', error) | ||
| } | ||
| } | ||
|  | ||
| if (this._logRecords.length > 0) { | ||
| this._startTimer() | ||
| } | ||
| } | ||
|  | ||
| _clearTimer () { | ||
| if (this._timer) { | ||
| clearTimeout(this._timer) | ||
| this._timer = null | ||
| } | ||
| } | ||
|  | ||
| forceFlush () { | ||
| return new Promise((resolve) => { | ||
| if (this._isShutdown) { | ||
| resolve() | ||
| return | ||
| } | ||
|  | ||
| this._export() | ||
| resolve() | ||
| }) | ||
| } | ||
|  | ||
| shutdown () { | ||
| if (this._isShutdown) { | ||
| return this._shutdownPromise || Promise.resolve() | ||
| } | ||
|  | ||
| this._isShutdown = true | ||
| this._shutdownPromise = new Promise((resolve) => { | ||
| this._clearTimer() | ||
|  | ||
| this._export() | ||
|  | ||
| const shutdownPromises = this._processors.map(processor => { | ||
| return typeof processor.shutdown === 'function' | ||
| ? processor.shutdown() | ||
| : Promise.resolve() | ||
| }) | ||
|  | ||
| Promise.all(shutdownPromises).then(resolve) | ||
| }) | ||
|  | ||
| return this._shutdownPromise | ||
| } | ||
| } | ||
|  | ||
| module.exports = BatchLogRecordProcessor | ||
  
    
      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,59 @@ | ||
| syntax = "proto3"; | ||
|  | ||
| package opentelemetry.proto.common.v1; | ||
|  | ||
| option go_package = "go.opentelemetry.io/collector/pdata/pcommon"; | ||
|  | ||
| // AnyValue is used to represent any type of attribute value. AnyValue may contain a | ||
| // simple scalar or an arbitrary complex structure including arrays and nested objects. | ||
| // AnyValue is a oneof type and can be one of the following: | ||
| // - string_value: A string value. | ||
| // - bool_value: A boolean value. | ||
| // - int_value: An integer value. | ||
| // - double_value: A double value. | ||
| // - array_value: An array of AnyValue values. | ||
| // - kvlist_value: A key-value list of AnyValue values. | ||
| // - bytes_value: A bytes value. | ||
| message AnyValue { | ||
| oneof value { | ||
| string string_value = 1; | ||
| bool bool_value = 2; | ||
| int64 int_value = 3; | ||
| double double_value = 4; | ||
| ArrayValue array_value = 5; | ||
| KeyValueList kvlist_value = 6; | ||
| bytes bytes_value = 7; | ||
| } | ||
| } | ||
|  | ||
| // ArrayValue is a list of AnyValue messages. We need ArrayValue as a message | ||
| // since oneof in AnyValue does not allow repeated fields. | ||
| message ArrayValue { | ||
| // Array of values. The array may be empty (contain 0 elements). | ||
| repeated AnyValue values = 1; | ||
| } | ||
|  | ||
| // KeyValueList is a list of KeyValue messages. We need KeyValueList as a message | ||
| // since oneof in AnyValue does not allow repeated fields. | ||
| message KeyValueList { | ||
| // A collection of key/value pairs of key-value pairs. The list may be empty (may | ||
| // contain 0 elements). | ||
| repeated KeyValue values = 1; | ||
| } | ||
|  | ||
| // KeyValue is a key-value pair that is used to store metadata about the telemetry | ||
| // record. | ||
| message KeyValue { | ||
| string key = 1; | ||
| AnyValue value = 2; | ||
| } | ||
|  | ||
| // InstrumentationScope is a message representing the instrumentation scope information | ||
| // such as the fully qualified name and version. | ||
| message InstrumentationScope { | ||
| // An empty instrumentation scope name means the name is unknown. | ||
| string name = 1; | ||
| string version = 2; | ||
| repeated KeyValue attributes = 3; | ||
| uint32 dropped_attributes_count = 4; | ||
| } | 
  
    
      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,22 @@ | ||
| 'use strict' | ||
|  | ||
| /** | ||
| * @fileoverview OpenTelemetry Logs Implementation for dd-trace-js | ||
| * | ||
| * Custom implementation to avoid pulling in the full OpenTelemetry SDK. | ||
| * Based on OTLP Protocol v1.7.0. | ||
| */ | ||
|  | ||
| const LoggerProvider = require('./logger_provider') | ||
| const Logger = require('./logger') | ||
| const BatchLogRecordProcessor = require('./batch_log_processor') | ||
| const OtlpHttpLogExporter = require('./otlp_http_log_exporter') | ||
| const OtlpTransformer = require('./otlp_transformer') | ||
|  | ||
| module.exports = { | ||
| LoggerProvider, | ||
| Logger, | ||
| BatchLogRecordProcessor, | ||
| OtlpHttpLogExporter, | ||
| OtlpTransformer | ||
| } | 
      
      Oops, something went wrong.
        
    
  
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.