Skip to content

Commit

Permalink
[exporter/loki] remove opencensus usage
Browse files Browse the repository at this point in the history
Fixes open-telemetry#30170

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten committed Jan 19, 2024
1 parent d8a5384 commit 9fd9ada
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
27 changes: 27 additions & 0 deletions .chloggen/codeboten_rm-census-loki.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: lokiexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: migrate metrics to use OpenTelemetry

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

# (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: []
14 changes: 12 additions & 2 deletions exporter/lokiexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"go.opencensus.io/stats"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/otel/metric"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/lokiexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/loki"
)

Expand All @@ -35,14 +36,23 @@ type lokiExporter struct {
settings component.TelemetrySettings
client *http.Client
wg sync.WaitGroup

lokiExporterFailedToSendLogRecordsDueToMissingLabels metric.Int64Counter
}

func newExporter(config *Config, settings component.TelemetrySettings) *lokiExporter {
settings.Logger.Info("using the new Loki exporter")

count, _ := metadata.Meter(settings).Int64Counter(
"lokiexporter_send_failed_due_to_missing_labels",
metric.WithDescription("Number of log records failed to send because labels were missing"),
metric.WithUnit("1"),
)

return &lokiExporter{
config: config,
settings: settings,
lokiExporterFailedToSendLogRecordsDueToMissingLabels: count,
}
}

Expand All @@ -53,7 +63,7 @@ func (l *lokiExporter) pushLogData(ctx context.Context, ld plog.Logs) error {
for tenant, request := range requests {
err := l.sendPushRequest(ctx, tenant, request, ld)
if isErrMissingLabels(err) {
stats.Record(ctx, lokiExporterFailedToSendLogRecordsDueToMissingLabels.M(int64(ld.LogRecordCount())))
l.lokiExporterFailedToSendLogRecordsDueToMissingLabels.Add(ctx, int64(ld.LogRecordCount()))
}

errs = multierr.Append(errs, err)
Expand Down
3 changes: 0 additions & 3 deletions exporter/lokiexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"time"

"go.opencensus.io/stats/view"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
Expand All @@ -22,8 +21,6 @@ import (

// NewFactory creates a factory for the legacy Loki exporter.
func NewFactory() exporter.Factory {
_ = view.Register(metricViews()...)

return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
Expand Down
2 changes: 1 addition & 1 deletion exporter/lokiexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/loki v0.92.0
github.com/prometheus/common v0.46.0
github.com/stretchr/testify v1.8.4
go.opencensus.io v0.24.0
go.opentelemetry.io/collector v0.92.1-0.20240118172122-8131d31601b8
go.opentelemetry.io/collector/component v0.92.1-0.20240118172122-8131d31601b8
go.opentelemetry.io/collector/config/confighttp v0.92.1-0.20240118172122-8131d31601b8
Expand Down Expand Up @@ -64,6 +63,7 @@ require (
github.com/prometheus/prometheus v0.48.1 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
github.com/rs/cors v1.10.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.92.1-0.20240118172122-8131d31601b8 // indirect
go.opentelemetry.io/collector/config/configcompression v0.92.1-0.20240118172122-8131d31601b8 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.92.1-0.20240118172122-8131d31601b8 // indirect
Expand Down
24 changes: 0 additions & 24 deletions exporter/lokiexporter/metrics.go

This file was deleted.

0 comments on commit 9fd9ada

Please sign in to comment.