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

Add custom tag to request metric #174

Closed
renyijiu opened this issue Jun 18, 2024 · 3 comments
Closed

Add custom tag to request metric #174

renyijiu opened this issue Jun 18, 2024 · 3 comments

Comments

@renyijiu
Copy link

The service is currently developed using connectrpc, and then plugged into the package to get the metrics, like rpc_server_request_size_bytes_bucket{otel_scope_name="connectrpc.com/otelconnect",otel_scope_version="semver:0.6.0-dev",rpc_grpc_status_code="0",rpc_method="GetProject",rpc_service="projectService",rpc_system="grpc",le="0"} 0

but i want to read specific fields from the request header and add them to metrics (example: orgId), I wonder if this operation is supported?

the init code:

	exporter, err := prometheus.New()
	if err != nil {
		log.Fatalf("unable to create promethe expoter")
	}
	// add custom label to all metrics

	meterProvider := metric.NewMeterProvider(metric.WithReader(exporter),
		metric.WithResource(
			resource.NewWithAttributes(
				semconv.SchemaURL,
				semconv.ServiceNameKey.String("your-service-name"),
				attribute.String("environment", "demo"),
			),
		),
	)
	otelInterceptor, err := otelconnect.NewInterceptor(
		otelconnect.WithMeterProvider(meterProvider),
		otelconnect.WithoutServerPeerAttributes(),
	)
@srikrsna-buf
Copy link
Member

srikrsna-buf commented Jun 21, 2024

Adding a metric attribute is documented here, it can be done via an interceptor. This is in addition to the interceptor in this library.

@jhump
Copy link
Member

jhump commented Jun 21, 2024

Closing this issue since I think @srikrsna-buf's response above contains the answer. @renyijiu, leave a comment if you need more information.

@jhump jhump closed this as completed Jun 21, 2024
@renyijiu
Copy link
Author

Thanks, I understand that this can be done when customizing the metric, but I would like to know if there is a way to add custom attributes to the library's default metrics, such as the metric data provided with the requests_per_rpc prefix by default

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

No branches or pull requests

3 participants