-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore][exporter/debug] refactor code to make independent from Loggin…
…g exporter (#9922) This PR is the first part of this draft PR: #9298. This refactoring is needed to implement [[exporter/debug] change behavior of "normal" verbosity to be different from "basic" #7806](#7806). I want to change the behavior of the Debug exporter, but leave the behavior of the Logging exporter unchanged. **Link to tracking Issue:** - #7806
- Loading branch information
1 parent
e8cabb7
commit 9731ea3
Showing
4 changed files
with
135 additions
and
18 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,87 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// NOTE: If you are making changes to this file, consider whether you want to make similar changes | ||
// to the Logging exporter in /exporter/internal/common/logging_exporter.go, which has similar logic. | ||
// This is especially important for security issues. | ||
|
||
package debugexporter // import "go.opentelemetry.io/collector/exporter/debugexporter" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
|
||
"go.opentelemetry.io/collector/config/configtelemetry" | ||
"go.opentelemetry.io/collector/exporter/internal/otlptext" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
) | ||
|
||
type debugExporter struct { | ||
verbosity configtelemetry.Level | ||
logger *zap.Logger | ||
logsMarshaler plog.Marshaler | ||
metricsMarshaler pmetric.Marshaler | ||
tracesMarshaler ptrace.Marshaler | ||
} | ||
|
||
func newDebugExporter(logger *zap.Logger, verbosity configtelemetry.Level) *debugExporter { | ||
return &debugExporter{ | ||
verbosity: verbosity, | ||
logger: logger, | ||
logsMarshaler: otlptext.NewTextLogsMarshaler(), | ||
metricsMarshaler: otlptext.NewTextMetricsMarshaler(), | ||
tracesMarshaler: otlptext.NewTextTracesMarshaler(), | ||
} | ||
} | ||
|
||
func (s *debugExporter) pushTraces(_ context.Context, td ptrace.Traces) error { | ||
s.logger.Info("TracesExporter", | ||
zap.Int("resource spans", td.ResourceSpans().Len()), | ||
zap.Int("spans", td.SpanCount())) | ||
if s.verbosity != configtelemetry.LevelDetailed { | ||
return nil | ||
} | ||
|
||
buf, err := s.tracesMarshaler.MarshalTraces(td) | ||
if err != nil { | ||
return err | ||
} | ||
s.logger.Info(string(buf)) | ||
return nil | ||
} | ||
|
||
func (s *debugExporter) pushMetrics(_ context.Context, md pmetric.Metrics) error { | ||
s.logger.Info("MetricsExporter", | ||
zap.Int("resource metrics", md.ResourceMetrics().Len()), | ||
zap.Int("metrics", md.MetricCount()), | ||
zap.Int("data points", md.DataPointCount())) | ||
if s.verbosity != configtelemetry.LevelDetailed { | ||
return nil | ||
} | ||
|
||
buf, err := s.metricsMarshaler.MarshalMetrics(md) | ||
if err != nil { | ||
return err | ||
} | ||
s.logger.Info(string(buf)) | ||
return nil | ||
} | ||
|
||
func (s *debugExporter) pushLogs(_ context.Context, ld plog.Logs) error { | ||
s.logger.Info("LogsExporter", | ||
zap.Int("resource logs", ld.ResourceLogs().Len()), | ||
zap.Int("log records", ld.LogRecordCount())) | ||
if s.verbosity != configtelemetry.LevelDetailed { | ||
return nil | ||
} | ||
|
||
buf, err := s.logsMarshaler.MarshalLogs(ld) | ||
if err != nil { | ||
return err | ||
} | ||
s.logger.Info(string(buf)) | ||
return nil | ||
} |
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