Skip to content

Commit

Permalink
[pkg/datadog] expose Zaplogger (open-telemetry#37939)
Browse files Browse the repository at this point in the history
#### Description
Expose the internal Zaplogger implementation so that it can be reused in
datadog-agent.
  • Loading branch information
songy23 authored Feb 14, 2025
1 parent 1c37438 commit 8c74228
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 89 deletions.
27 changes: 27 additions & 0 deletions .chloggen/dd-logger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/datadog

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Expose the internal Zaplogger implementation

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [37939]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
6 changes: 4 additions & 2 deletions exporter/datadogexporter/agent_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"go.opentelemetry.io/collector/component"

pkgdatadog "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog"
)

func newLogComponent(set component.TelemetrySettings) corelog.Component {
zlog := &zaplogger{
logger: set.Logger,
zlog := &pkgdatadog.Zaplogger{
Logger: set.Logger,
}
return zlog
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,6 @@ func newTraceAgentConfig(ctx context.Context, params exporter.Settings, cfg *Con
if !datadog.ReceiveResourceSpansV2FeatureGate.IsEnabled() {
acfg.Features["disable_receive_resource_spans_v2"] = struct{}{}
}
tracelog.SetLogger(&zaplogger{params.Logger}) // TODO: This shouldn't be a singleton
tracelog.SetLogger(&datadog.Zaplogger{Logger: params.Logger}) // TODO: This shouldn't be a singleton
return acfg, nil
}
80 changes: 0 additions & 80 deletions exporter/datadogexporter/zaplogger.go

This file was deleted.

5 changes: 3 additions & 2 deletions pkg/datadog/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog
go 1.23.0

require (
github.com/DataDog/datadog-agent/pkg/trace v0.62.2
github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.62.2
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.25.0
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.25.0
Expand Down Expand Up @@ -34,7 +35,7 @@ require (
github.com/DataDog/opentelemetry-mapping-go/pkg/inframetadata v0.25.0 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.25.0 // indirect
github.com/DataDog/sketches-go v1.4.6 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/DataDog/zstd v1.5.6 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.26.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.36.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.29.6 // indirect
Expand Down Expand Up @@ -136,7 +137,7 @@ require (
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241230172942-26aa7a208def // indirect
google.golang.org/grpc v1.70.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
Expand Down
10 changes: 6 additions & 4 deletions pkg/datadog/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions pkg/datadog/zaplogger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package datadog // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog"

import (
"fmt"

tracelog "github.com/DataDog/datadog-agent/pkg/trace/log"
"go.uber.org/zap"
)

var _ tracelog.Logger = &Zaplogger{}

// Zaplogger implements the tracelog.Logger interface on top of a zap.Logger
type Zaplogger struct {
// Logger is the internal zap logger
Logger *zap.Logger
}

// Trace implements Logger.
func (z *Zaplogger) Trace(_ ...any) { /* N/A */ }

// Tracef implements Logger.
func (z *Zaplogger) Tracef(_ string, _ ...any) { /* N/A */ }

// Debug implements Logger.
func (z *Zaplogger) Debug(v ...any) {
z.Logger.Debug(fmt.Sprint(v...))
}

// Debugf implements Logger.
func (z *Zaplogger) Debugf(format string, params ...any) {
z.Logger.Debug(fmt.Sprintf(format, params...))
}

// Info implements Logger.
func (z *Zaplogger) Info(v ...any) {
z.Logger.Info(fmt.Sprint(v...))
}

// Infof implements Logger.
func (z *Zaplogger) Infof(format string, params ...any) {
z.Logger.Info(fmt.Sprintf(format, params...))
}

// Warn implements Logger.
func (z *Zaplogger) Warn(v ...any) error {
z.Logger.Warn(fmt.Sprint(v...))
return nil
}

// Warnf implements Logger.
func (z *Zaplogger) Warnf(format string, params ...any) error {
z.Logger.Warn(fmt.Sprintf(format, params...))
return nil
}

// Error implements Logger.
func (z *Zaplogger) Error(v ...any) error {
z.Logger.Error(fmt.Sprint(v...))
return nil
}

// Errorf implements Logger.
func (z *Zaplogger) Errorf(format string, params ...any) error {
z.Logger.Error(fmt.Sprintf(format, params...))
return nil
}

// Critical implements Logger.
func (z *Zaplogger) Critical(v ...any) error {
z.Logger.Error(fmt.Sprint(v...), zap.Bool("critical", true))
return nil
}

// Criticalf implements Logger.
func (z *Zaplogger) Criticalf(format string, params ...any) error {
z.Logger.Error(fmt.Sprintf(format, params...), zap.Bool("critical", true))
return nil
}

// Flush implements Logger.
func (z *Zaplogger) Flush() {
_ = z.Logger.Sync()
}

0 comments on commit 8c74228

Please sign in to comment.