Skip to content

feat: logs SDK observability - otlploggrpc exporter metrics #7084

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

yumosx
Copy link
Contributor

@yumosx yumosx commented Jul 25, 2025

fix #7019

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

❌ Patch coverage is 81.88406% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.9%. Comparing base (affc1a2) to head (0c7a55b).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
exporters/otlp/otlplog/otlploggrpc/client.go 77.6% 20 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##            main   #7084    +/-   ##
======================================
  Coverage   82.9%   82.9%            
======================================
  Files        262     263     +1     
  Lines      24460   24597   +137     
======================================
+ Hits       20281   20395   +114     
- Misses      3801    3819    +18     
- Partials     378     383     +5     
Files with missing lines Coverage Δ
exporters/otlp/otlplog/otlploggrpc/internal/x/x.go 100.0% <100.0%> (ø)
exporters/otlp/otlplog/otlploggrpc/client.go 85.4% <77.6%> (-6.5%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -19,12 +22,28 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"go.opentelemetry.io/otel/attribute"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank lines, they need to be grouped together.

if resp != nil && resp.PartialSuccess != nil {
msg := resp.PartialSuccess.GetErrorMessage()
n := resp.PartialSuccess.GetRejectedLogRecords()
if n != 0 || msg != "" {
err := fmt.Errorf("OTLP partial success: %s (%d log records rejected)", msg, n)
c.recordLogInflightMetric(ctx, attribute.String("error.type", err.Error()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx like these should, in theory, be detached from the contextual background.

Temporarily marked as an interrogative stance.

@yumosx
Copy link
Contributor Author

yumosx commented Jul 25, 2025

Good suggestion, done.

collogpb "go.opentelemetry.io/proto/otlp/collector/logs/v1"
logpb "go.opentelemetry.io/proto/otlp/logs/v1"
)

var (
componentType = otelconv.ComponentTypeOtlpGRPCLogExporter
exporterInstanceCounter int64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would be safer to use atomic.Int64 directly here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, this is my oversight. I'll fix it.

if resp != nil && resp.PartialSuccess != nil {
msg := resp.PartialSuccess.GetErrorMessage()
n := resp.PartialSuccess.GetRejectedLogRecords()
if n != 0 || msg != "" {
err := fmt.Errorf("OTLP partial success: %s (%d log records rejected)", msg, n)
c.recordLogInflightMetric(context.Background(), attribute.String("error.type", err.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, error type is supposed to be one of a specific set of errors to prevent cardinality explosion. See https://github.com/open-telemetry/opentelemetry-go-contrib/blob/e09bd7c580cdc6bc48e9da8ac832665e5a2ce314/instrumentation/net/http/otelhttp/internal/semconv/httpconv.go#L411 for an example of what otelhttp does.

c.logExportedDurationMetric.Record(ctx, duration, attrs...)
}

func (c *client) getPort() int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we compute this on client initialization so we don't need to do it each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logs SDK observability - otlploggrpc exporter metrics
3 participants