Skip to content

Commit

Permalink
add basic metric support
Browse files Browse the repository at this point in the history
  • Loading branch information
Frapschen committed Jan 9, 2023
1 parent 5d330b6 commit be01edc
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#663](https://github.com/open-telemetry/opentelemetry-demo/pull/663))
* Add `OTEL_RESOURCE_ATTRIBUTES` to docker compose setup
([#664](https://github.com/open-telemetry/opentelemetry-demo/pull/664))
* Add basic metric support to productcatalog service
([#674](https://github.com/open-telemetry/opentelemetry-demo/pull/674))
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ services:
- PRODUCT_CATALOG_SERVICE_PORT
- FEATURE_FLAG_GRPC_SERVICE_ADDR
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
- OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
- OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
- OTEL_RESOURCE_ATTRIBUTES
- OTEL_SERVICE_NAME=productcatalogservice
depends_on:
Expand Down
8 changes: 4 additions & 4 deletions docs/metric_service_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Emoji Legend
- Not Present (Yet): :construction:

| Service | Language | Auto Instrumentation | Manual Metric Creation | Collector Agent Metric Transformation | Push Metrics | SLO Metrics | Multiple Manual Metric Instruments |
|-----------------|-----------------|----------------------|------------------------|---------------------------------------|----------------|----------------|------------------------------------|
| --------------- | --------------- | -------------------- | ---------------------- | ------------------------------------- | -------------- | -------------- | ---------------------------------- |
| Ad | Java | :100: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Cart | .NET | :100: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Checkout | Go | :100: | :construction: | :construction: | :construction: | :construction: | :construction: |
Expand All @@ -16,6 +16,6 @@ Emoji Legend
| Feature Flag | Erlang / Elixir | :construction: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Frontend | JavaScript | :construction: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Payment | JavaScript | :construction: | :100: | :construction: | :construction: | :construction: | :construction: |
| Product Catalog | Go | :construction: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Recommendation | Python | :100: | :100: | :construction: | :construction: | :construction: | :construction: |
| Shipping | Rust | :construction: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Product Catalog | Go | :100: | :construction: | :construction: | :construction: | :construction: | :construction: |
| Recommendation | Python | :100: | :100: | :construction: | :construction: | :construction: | :construction: |
| Shipping | Rust | :construction: | :construction: | :construction: | :construction: | :construction: | :construction: |
44 changes: 43 additions & 1 deletion docs/services/productcatalogservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,49 @@ or when a product is successfully found.

## Metrics

TBD
### Initializing Metrics

The OpenTelemetry SDK is initialized from `main` using the `initMeterProvider`
function.

```go
func initMeterProvider() *sdkmetric.MeterProvider {
ctx := context.Background()

exporter, err := otlpmetricgrpc.New(ctx)
if err != nil {
log.Fatalf("new otlp metric grpc exporter failed: %v", err)
}

mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(sdkmetric.NewPeriodicReader(exporter)))
global.SetMeterProvider(mp)
return mp
}
```

You should call `initMeterProvider.Shutdown()` when your service is shutdown to
ensure all records are exported. This service makes that call as part of a
deferred function in main

```go
mp := initMeterProvider()
defer func() {
if err := mp.Shutdown(context.Background()); err != nil {
log.Fatalf("Error shutting down meter provider: %v", err)
}
}()
```

### Adding golang runtime auto-instrumentation

Golang runtime are instrumented in the main function

```go
err := runtime.Start(runtime.WithMinimumReadMemStatsInterval(time.Second))
if err != nil {
log.Fatal(err)
}
```

## Logs

Expand Down
34 changes: 19 additions & 15 deletions src/productcatalogservice/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@ go 1.17

require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7
github.com/sirupsen/logrus v1.8.1
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
google.golang.org/grpc v1.44.0
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
google.golang.org/grpc v1.51.0
)

require (
go.opentelemetry.io/otel/sdk v1.4.1
google.golang.org/protobuf v1.27.1
go.opentelemetry.io/contrib/instrumentation/runtime v0.37.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.34.0
go.opentelemetry.io/otel/metric v0.34.0
go.opentelemetry.io/otel/sdk v1.11.2
go.opentelemetry.io/otel/sdk/metric v0.34.0
go.opentelemetry.io/otel/trace v1.11.2
google.golang.org/protobuf v1.28.1
)

require (
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.4.1 // indirect
go.opentelemetry.io/otel/trace v1.4.1 // indirect
go.opentelemetry.io/proto/otlp v0.12.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.2 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
)

require (
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.29.0
go.opentelemetry.io/otel v1.4.1
go.opentelemetry.io/otel v1.11.2
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.4.1
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 // indirect
)
Loading

0 comments on commit be01edc

Please sign in to comment.