Skip to content

Conversation

@py4chen
Copy link
Contributor

@py4chen py4chen commented Oct 22, 2025

Description

This PR enables SIA users to specify http://<collector-endpoint>:<port> and grpc://<collector-endpoint>:<port> in the otel config.

Verification (HTTP)

  • Ran an otel collector with the following config:
receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318
  • Execute the following go code to invoke the otel package:
func main() {
	cfg := config.OTel{
		CollectorEndpoint: otelColEndpoint,
		CACertPath:        caCertPath,
	}
	shutdownFn := myotel.StartOTelProvider(cfg)
	shutdownFlush := func() {
		shutdownCtx, cancel := context.WithTimeout(context.Background(), time.Second*2)
		if err := shutdownFn(shutdownCtx); err != nil {
			log.Printf("failed to shut down oTel provider: %v", err)
		}
		cancel()
	}
	defer shutdownFlush()

	meter := otel.GetMeterProvider().Meter("otel-sender")

	mGauge, err := meter.Int64Gauge(
		"my-gauge",
		metric.WithUnit("1"),
	)
	if err != nil {
		log.Printf("Error creating metric %v", err)
	}

	mGauge.Record(context.Background(), 123)

	fmt.Println("completed")
}
  • can successfully find the metrics sent to the collector
InstrumentationScope otel-sender 
Metric #0
Descriptor:
     -> Name: my-gauge
     -> Description: 
     -> Unit: 1
     -> DataType: Gauge
NumberDataPoints #0
StartTimestamp: 2025-10-23 13:03:42.285714 +0000 UTC
Timestamp: 2025-10-23 13:03:42.285758 +0000 UTC
Value: 123
        {"resource": {"service.instance.id": "73a3927d-1807-4d86-b11c-3479d8a6c910", "service.name": "otelcol", "service.version": "0.137.0"}, "otelcol.component.id": "debug", "otelcol.component.kind": "exporter", "otelcol.signal": "metrics"}

Contribution Checklist:

  • The pull request does not introduce any breaking changes
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Attach Screenshots (Optional)

@py4chen py4chen changed the title DNR: support HTTP & GRPC in sia otel instrumentation support HTTP & GRPC protocol in sia otel instrumentation Oct 23, 2025
@py4chen py4chen marked this pull request as ready for review October 23, 2025 12:39
Signed-off-by: Po-Yao Chen <[email protected]>
@havetisyan
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for both HTTP and gRPC protocols for the OpenTelemetry collector endpoint, allowing users to specify the protocol in the endpoint URL. The changes are well-structured, introducing protocol detection logic and conditional exporter creation for gRPC and HTTP. Comprehensive tests for HTTP, HTTPS, and gRPC have been added, which is excellent. I have a few suggestions to improve the robustness of the protocol detection logic and to align error handling with common Go practices. Overall, this is a valuable enhancement to the SIA OTEL instrumentation.

Po-Yao Chen added 2 commits October 23, 2025 16:35
Signed-off-by: Po-Yao Chen <[email protected]>
Signed-off-by: Po-Yao Chen <[email protected]>
@py4chen
Copy link
Contributor Author

py4chen commented Oct 23, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for HTTP and gRPC protocols in the SIA OTel instrumentation. It includes changes to go.mod, go.sum, config.go, and introduces new files for metric sending and utility functions. The changes allow users to specify collector endpoints with HTTP/HTTPS/GRPC schemes. I have provided review comments to address potential issues and improve the code.

Signed-off-by: Po-Yao Chen <[email protected]>
@py4chen
Copy link
Contributor Author

py4chen commented Oct 23, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for both HTTP and gRPC protocols for OpenTelemetry metric exporting. The changes include adding the gRPC OTLP exporter dependency, refactoring the metric sender to dynamically choose the exporter based on the collector endpoint URL, and adding utility functions for protocol detection. The implementation is supported by a comprehensive set of new unit tests for HTTP, HTTPS, and gRPC scenarios.

My review focuses on the robustness of the new protocol detection logic. I've identified a potential issue in the isGRPCProtocol utility function that could lead to incorrect protocol detection in some edge cases and have suggested a more robust implementation. I've also recommended adding more test cases to cover these edge cases. Overall, this is a great addition that increases the flexibility of the OTel instrumentation.

Signed-off-by: Po-Yao Chen <[email protected]>
@havetisyan havetisyan merged commit 57c0de1 into AthenZ:master Oct 23, 2025
3 checks passed
@py4chen py4chen deleted the pchen06/grpc-http branch October 24, 2025 11:30
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.

2 participants