-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
examples/features/opentelemetry: demonstrate tracing using OpenTelemetry plugin #8056
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8056 +/- ##
==========================================
- Coverage 82.16% 82.13% -0.03%
==========================================
Files 410 410
Lines 40248 40248
==========================================
- Hits 33068 33059 -9
- Misses 5830 5833 +3
- Partials 1350 1356 +6 🚀 New features to boost your workflow:
|
f463f2b
to
58451b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janardhanvissa please use any of the trace exporter from here https://opentelemetry.io/docs/languages/go/exporters/. May be otlptracehttp or stdouttrace are good candidates
Also, please refer to https://opentelemetry.io/docs/languages/go/getting-started/ for writing otel trace exporting parts in client and server. We should try to avoid as much custom code as possible here to make it easy and fast for users to pick up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janardhanvissa i discussed with @dfawley and we are fine with using console exporter instead for the tracing example so that we don't have install extra stufff. Please modify the example using the console exporter
examples/go.mod
Outdated
// | ||
// For the OpenTelemetry Collector Core distribution specifically, see | ||
// https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: // Documentation:
// The builder manifests used for official OpenTelemetry Collector binaries
// can be found at the following repository:
// https://github.com/open-telemetry/opentelemetry-collector-releases
//
// For the OpenTelemetry Collector Core distribution specifically, refer to:
// https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs are for the OpenTelemetry Collector, which we're not using; we're using stdouttrace instead. These things are already removed from the go.mod.
// the client and the server. | ||
for { | ||
r, err := c.UnaryEcho(ctx, &echo.EchoRequest{Message: "this is examples/opentelemetry"}) | ||
if err != nil { | ||
log.Fatalf("UnaryEcho failed: %v", err) | ||
} | ||
fmt.Println(r) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove the extra space
@@ -51,14 +60,47 @@ func (s *echoServer) UnaryEcho(_ context.Context, req *pb.EchoRequest) (*pb.Echo | |||
} | |||
|
|||
func main() { | |||
flag.Parse() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Remove the extra space and check the other places as well
OpenTelemetry is configured on both the client and the server, and exports to | ||
the Prometheus exporter. The exporter exposes metrics on the Prometheus ports | ||
described above. | ||
OpenTelemetry is configured on both the client and the server, and exports metrics to the Prometheus exporter. The exporter exposes metrics on the Prometheus ports described above. OpenTelemetry also exports traces using the stdouttrace exporter. These traces are printed as structured data to the console output of both the client and the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenTelemetry is configured on both the client and the server, and exports metrics to the Prometheus exporter. The exporter exposes metrics on the Prometheus ports described above. OpenTelemetry also exports traces using the stdouttrace exporter. These traces are printed as structured data to the console output of both the client and the server. | |
OpenTelemetry is configured on both the client and the server, and exports metrics to the Prometheus exporter. The exporter exposes metrics on the Prometheus ports described above. | |
OpenTelemetry exports traces using the stdouttrace exporter, which prints structured trace data to the console output of both the client and server. Each RPC call produces trace information that captures the execution flow and timing of operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janardhanvissa in README.md, please all sentences to 80 cols.
@@ -1,10 +1,13 @@ | |||
# OpenTelemetry | |||
|
|||
This example shows how to configure OpenTelemetry on a client and server, and shows | |||
what type of telemetry data it can produce for certain RPC's. | |||
This example shows how to configure OpenTelemetry on a client and server, and shows what type of telemetry data it can produce for certain RPC's. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restrict the sentences to 80 cols. What is the change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reached 80 cols, so moved to the next line.
|
||
## Try it | ||
|
||
This section shows how to configure OpenTelemetry Metrics and Traces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove this I think. The first sentence is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
## Try it | ||
|
||
This section shows how to configure OpenTelemetry Metrics and Traces. | ||
|
||
**1. Run the gRPC Applications:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. No need of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -13,20 +16,18 @@ go run server/main.go | |||
go run client/main.go | |||
``` | |||
|
|||
**2. View Telemetry Data:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
The client continuously makes RPC's to a server. The client and server both | ||
expose a prometheus exporter to listen and provide metrics. This defaults to | ||
:9464 for the server and :9465 for the client. | ||
The client continuously makes RPC's to a server. The client and server both expose a Prometheus exporter to listen and provide metrics. This defaults to :9464 for the server and :9465 for the client. The client and server are also configured to output traces directly to their standard output streams using stdouttrace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap stdouttrace within backticks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
) | ||
|
||
func main() { | ||
exporter, err := prometheus.New() | ||
flag.Parse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this flag.Parse()? or it can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
if err != nil { | ||
log.Fatalf("Failed to start prometheus exporter: %v", err) | ||
} | ||
provider := metric.NewMeterProvider(metric.WithReader(exporter)) | ||
go http.ListenAndServe(*prometheusEndpoint, promhttp.Handler()) | ||
// Initialize MeterProvider with Prometheus exporter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need of this comment. Actually there is no change needed here. It can be reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
) | ||
|
||
var ( | ||
addr = flag.String("addr", ":50051", "the server address to connect to") | ||
prometheusEndpoint = flag.String("prometheus_endpoint", ":9464", "the Prometheus exporter endpoint") | ||
prometheusEndpoint = flag.String("prometheus_endpoint", ":9464", "the Prometheus exporter endpoint for metrics") | ||
serviceName = "grpc-server" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. Do we need this? or it can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to set the service name as an attribute in the resource information attached to the traces for the server.
@@ -51,14 +57,28 @@ func (s *echoServer) UnaryEcho(_ context.Context, req *pb.EchoRequest) (*pb.Echo | |||
} | |||
|
|||
func main() { | |||
exporter, err := prometheus.New() | |||
flag.Parse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. do we need this? or it can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
if err != nil { | ||
log.Fatalf("Failed to start prometheus exporter: %v", err) | ||
} | ||
provider := metric.NewMeterProvider(metric.WithReader(exporter)) | ||
go http.ListenAndServe(*prometheusEndpoint, promhttp.Handler()) | ||
// Initialize MeterProvider with Prometheus exporter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. No need of any change here. Let it be how it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
) | ||
|
||
func main() { | ||
exporter, err := prometheus.New() | ||
if err != nil { | ||
log.Fatalf("Failed to start prometheus exporter: %v", err) | ||
} | ||
provider := metric.NewMeterProvider(metric.WithReader(exporter)) | ||
go http.ListenAndServe(*prometheusEndpoint, promhttp.Handler()) | ||
provider := otelmetric.NewMeterProvider(otelmetric.WithReader(exporter)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: one comment above "Configure meter provider for metrics"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if err != nil { | ||
log.Fatalf("Failed to create stdouttrace exporter: %v", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
log.Fatalf("Failed to create stdouttrace exporter: %v", err) | ||
} | ||
|
||
// Configure the tracer provider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
// Configure the tracer provider | ||
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(traceExporter), sdktrace.WithResource(otelresource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceName(serviceName)))) | ||
textMapPropagator := otelpropagation.TraceContext{} // Using W3C Trace Context Propagator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
textMapPropagator := otelpropagation.TraceContext{} // Using W3C Trace Context Propagator. | |
// Configure W3C Trace Context Propagator for traces | |
textMapPropagator := otelpropagation.TraceContext{} // Using W3C Trace Context Propagator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
ctx := context.Background() | ||
do := opentelemetry.DialOption(opentelemetry.Options{MetricsOptions: opentelemetry.MetricsOptions{MeterProvider: provider}}) | ||
// Initialize stdouttrace exporter for traces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace comment with "Configure exporter for traces"
// Initialize stdouttrace exporter for traces | |
// Configure exporter for traces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@janardhanvissa could you add the screenshots of traces on clients and server please? |
Server Client |
RELEASE NOTES: