-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pkg/otlp/logs] Switch to Translator design (#230)
* [pkg/otlp/logs] Switch to Translator design * Address feedback * Add changelog note
- Loading branch information
Showing
6 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: deprecation | ||
|
||
# The name of the component (e.g. pkg/quantile) | ||
component: pkg/otlp/logs | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Deprecate `logs.Transform` in favor of `logs.Translator` | ||
|
||
# The PR related to this change | ||
issues: [230] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
This file contains 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 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 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
File renamed without changes.
This file contains 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,63 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package logs | ||
|
||
import ( | ||
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
) | ||
|
||
// Translator of OTLP logs to Datadog format | ||
type Translator struct { | ||
set component.TelemetrySettings | ||
otelTag string | ||
} | ||
|
||
// NewTranslator returns a new Translator | ||
func NewTranslator(set component.TelemetrySettings, otelSource string) (*Translator, error) { | ||
return &Translator{ | ||
set: set, | ||
otelTag: "otel_source:" + otelSource, | ||
}, nil | ||
} | ||
|
||
// MapLogs from OTLP format to Datadog format. | ||
func (t *Translator) MapLogs(ld plog.Logs) []datadogV2.HTTPLogItem { | ||
rsl := ld.ResourceLogs() | ||
var payloads []datadogV2.HTTPLogItem | ||
for i := 0; i < rsl.Len(); i++ { | ||
rl := rsl.At(i) | ||
sls := rl.ScopeLogs() | ||
res := rl.Resource() | ||
for j := 0; j < sls.Len(); j++ { | ||
sl := sls.At(j) | ||
lsl := sl.LogRecords() | ||
// iterate over Logs | ||
for k := 0; k < lsl.Len(); k++ { | ||
log := lsl.At(k) | ||
payload := Transform(log, res, t.set.Logger) | ||
ddtags := payload.GetDdtags() | ||
if ddtags != "" { | ||
payload.SetDdtags(ddtags + "," + t.otelTag) | ||
} else { | ||
payload.SetDdtags(t.otelTag) | ||
} | ||
payloads = append(payloads, payload) | ||
} | ||
} | ||
} | ||
return payloads | ||
} |