Skip to content
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

feat: instrument grpc client with otel #39

Merged
merged 3 commits into from
Sep 18, 2024
Merged

Conversation

haoqixu
Copy link
Contributor

@haoqixu haoqixu commented Aug 21, 2024

What's changed and what's your intention?

This PR instruments the grpc client with otelgrpc and provides configurable settings for SDK telemetry.

Differences from #8

The main differences are:

  • This PR uses opentelemetry SDK instead of prometheus SDK and collects not only metrics but also traces.
  • This PR does not make decisions for users about observability strategy like metrics format, prometheus endpoint and metrics prefix/namespace. Users can provide their own MeterProvider/TracerProvider to decide their observability strategy and easily integrate the SDK telemetry into the application by reusing the providers.

If we already instrument our services with prometheus and want to integrate greptimedb-ingester-go, we can do it like:

package main

import (
	// ...

	otelprom "go.opentelemetry.io/otel/exporters/prometheus"
	"go.opentelemetry.io/otel/sdk/metric"

	// ...
)

func main() {
	// Register to the default global prometheus.Registerer.
	// We can also pass a prometheus.Registerer to otelprom.New(), or use exporter as prometheus.Collector
	exporter, err := otelprom.New(otelprom.WithNamespace("greptime"))
	if err != nil {
		log.Fatal(err)
	}
	meterProvider := metric.NewMeterProvider(
		metric.WithReader(exporter),
	)

	cfg := greptime.NewConfig("localhost").
		WithMetricsEnabled(true).  // enable it
		WithMeterProvider(meterProvider).  // custom provider, nil to use otel global meter provider
		WithDatabase("public")

	// ...
}

Maybe we can add the snippet to examples. 🤔

Checklist

  • I have added the necessary unit tests and integration tests.

Refer to a related PR or issue link (optional)

Fixes #8

@daviderli614
Copy link
Member

daviderli614 commented Sep 8, 2024

Thank for your contribution. Can you fix the CI error? @haoqixu
It seems that the new file not have a License header, and build errors.

- instrument grpc client with otelgrpc
- provide options to enable/disable telemetry
- provide options to set otel Providers
Copy link
Member

@daviderli614 daviderli614 left a comment

Choose a reason for hiding this comment

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

LGTM

@daviderli614 daviderli614 merged commit d3f1530 into GreptimeTeam:main Sep 18, 2024
6 checks passed
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.

collect critical metrics
2 participants