OpenTelemetry Tracing Examples
Code Source: https://github.com/gogf/examples/tree/main/observability/trace/otlp
Description
This directory contains examples demonstrating different methods of exporting OpenTelemetry trace data in GoFrame applications. It includes:
-
gRPC-based Export (
grpc/
)- Uses gRPC protocol for trace data transmission
- Suitable for high-performance, streaming trace data export
- Supports bidirectional streaming and connection multiplexing
-
HTTP-based Export (
http/
)- Uses HTTP protocol for trace data transmission
- Suitable for environments with HTTP proxy or firewall restrictions
- Simpler to configure and debug
Directory Structure
.
├── grpc/ # gRPC-based tracing example
│ └── main.go # gRPC trace exporter implementation
├── http/ # HTTP-based tracing example
│ └── main.go # HTTP trace exporter implementation
├── go.mod # Go module file
└── go.sum # Go module checksums
Requirements
Prerequisites
- Running Jaeger instance:
docker run --rm --name jaeger \
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
-p 14250:14250 \
-p 14268:14268 \
-p 14269:14269 \
-p 9411:9411 \
jaegertracing/all-in-one:1.55
Comparison of Export Methods
gRPC Export (grpc/)
-
Advantages:
- Higher performance
- Bidirectional streaming
- Connection multiplexing
- Better for high-volume tracing
-
Configuration:
- Requires gRPC endpoint
- Supports authentication token
- Configurable connection settings
-
Use Cases:
- High-volume trace data
- Microservices architecture
- Performance-critical systems
HTTP Export (http/)
-
Advantages:
- Simpler setup
- Works through HTTP proxies
- Easier to debug
- Better firewall compatibility
-
Configuration:
- Requires HTTP endpoint
- Supports path configuration
- Standard HTTP settings
-
Use Cases:
- Environments with HTTP proxy
- Simpler deployment requirements
- Development and testing
Usage
gRPC Export Example
-
Navigate to gRPC example:
cd grpc
-
Run the example:
go run main.go
HTTP Export Example
-
Navigate to HTTP example:
cd http
-
Run the example:
go run main.go
-
View traces: Open http://localhost:16686 in your browser to view traces in Jaeger UI.
Implementation Details
Both examples demonstrate:
-
Trace Context Management
- Span creation and management
- Context propagation
- Baggage handling
-
Error Handling
- Connection error handling
- Export error handling
- Graceful shutdown
-
Configuration
- Service name configuration
- Endpoint configuration
- Authentication setup
Troubleshooting
-
gRPC Export Issues:
- Check gRPC endpoint accessibility
- Verify authentication token
- Review gRPC connection logs
-
HTTP Export Issues:
- Check HTTP endpoint accessibility
- Verify path configuration
- Review HTTP response codes
-
General Issues:
- Verify Jaeger is running
- Check network connectivity
- Review application logs