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

[demo/accountingservice] instrument by OTel .NET Auto #4448

Merged
merged 9 commits into from
Jul 2, 2024
25 changes: 13 additions & 12 deletions content/en/docs/demo/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,25 @@ Want to deploy the demo and see it in action? Start here.
Want to understand how a particular language's instrumentation works? Start
here.

| Language | Automatic Instrumentation | Instrumentation Libraries | Manual Instrumentation |
| ---------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| .NET | | [Cart Service](services/cart/) | [Cart Service](services/cart/) |
| C++ | | | [Currency Service](services/currency/) |
| Go | | [Accounting Service](services/accounting/), [Checkout Service](services/checkout/), [Product Catalog Service](services/product-catalog/) | [Checkout Service](services/checkout/), [Product Catalog Service](services/product-catalog/) |
| Java | [Ad Service](services/ad/) | | [Ad Service](services/ad/) |
| JavaScript | | [Frontend](services/frontend/) | [Frontend](services/frontend/), [Payment Service](services/payment/) |
| Kotlin | | [Fraud Detection Service](services/fraud-detection/) | |
| PHP | | [Quote Service](services/quote/) | [Quote Service](services/quote/) |
| Python | [Recommendation Service](services/recommendation/) | | [Recommendation Service](services/recommendation/) |
| Ruby | | [Email Service](services/email/) | [Email Service](services/email/) |
| Rust | | [Shipping Service](services/shipping/) | [Shipping Service](services/shipping/) |
| Language | Automatic Instrumentation | Instrumentation Libraries | Manual Instrumentation |
| ---------- | -------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| .NET | [Accounting Service](services/accounting/) | [Cart Service](services/cart/) | [Cart Service](services/cart/) |
| C++ | | | [Currency Service](services/currency/) |
| Go | | [Checkout Service](services/checkout/), [Product Catalog Service](services/product-catalog/) | [Checkout Service](services/checkout/), [Product Catalog Service](services/product-catalog/) |
| Java | [Ad Service](services/ad/) | | [Ad Service](services/ad/) |
| JavaScript | | [Frontend](services/frontend/) | [Frontend](services/frontend/), [Payment Service](services/payment/) |
| Kotlin | | [Fraud Detection Service](services/fraud-detection/) | |
| PHP | | [Quote Service](services/quote/) | [Quote Service](services/quote/) |
| Python | [Recommendation Service](services/recommendation/) | | [Recommendation Service](services/recommendation/) |
| Ruby | | [Email Service](services/email/) | [Email Service](services/email/) |
| Rust | | [Shipping Service](services/shipping/) | [Shipping Service](services/shipping/) |

## Service Documentation

Specific information about how OpenTelemetry is deployed in each service can be
found here:

- [Accounting Service](services/accounting/)
- [Ad Service](services/ad/)
- [Cart Service](services/cart/)
- [Checkout Service](services/checkout/)
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/demo/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ generator which uses [Locust](https://locust.io/) to fake user traffic.
```mermaid
graph TD
subgraph Service Diagram
accountingservice(Accounting Service):::golang
accountingservice(Accounting Service):::dotnet
adservice(Ad Service):::java
cache[(Cache<br/>&#40redis&#41)]
cartservice(Cart Service):::dotnet
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/demo/services/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To visualize request flows, see the [Service Diagram](../architecture/).

| Service | Language | Description |
| ----------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| [accountingservice](accounting/) | Go | Processes incoming orders and count the sum of all orders (mock/). |
| [accountingservice](accounting/) | .NET | Processes incoming orders and count the sum of all orders (mock/). |
| [adservice](ad/) | Java | Provides text ads based on given context words. |
| [cartservice](cart/) | .NET | Stores the items in the user's shopping cart in Redis and retrieves it. |
| [checkoutservice](checkout/) | Go | Retrieves user cart, prepares order and orchestrates the payment, shipping and the email notification. |
Expand Down
60 changes: 13 additions & 47 deletions content/en/docs/demo/services/accounting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,28 @@
title: Accounting Service
linkTitle: Accounting
aliases: [accountingservice]
cSpell:ignore: otelsarama otlptracegrpc sarama sdktrace
---

This service calculates the total amount of sold products. This is only mocked
and received orders are printed out.

[Accounting Service](https://github.com/open-telemetry/opentelemetry-demo/blob/main/src/accountingservice/)

## Traces
## Auto-instrumentation

### Initializing Tracing
This service relies on the OpenTelemetry .NET Automatic Instrumentation to
automatically instrument libraries such as Kafka, and to configure the
OpenTelemetry SDK. The instrumentation is added via Nuget package
[OpenTelemetry.AutoInstrumentation](https://www.nuget.org/packages/OpenTelemetry.AutoInstrumentation)
and activated using environment variables that are sourced from `instrument.sh`.
Using this installation approach also guarantees that all instrumentation
dependencies are properly aligned with the application.

The OpenTelemetry SDK is initialized from `main` using the `initTracerProvider`
function.
## Publishing

```go
func initTracerProvider() (*sdktrace.TracerProvider, error) {
ctx := context.Background()
Add `--use-current-runtime` to the `dotnet publish` command to distribute
appropriate native runtime components.

exporter, err := otlptracegrpc.New(ctx)
if err != nil {
return nil, err
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(initResource()),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
return tp, nil
}
```

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

```go
tp, err := initTracerProvider()
if err != nil {
log.Fatal(err)
}
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Printf("Error shutting down tracer provider: %v", err)
}
}()
```

### Adding Kafka ( Sarama ) auto-instrumentation

This service will receive the processed results of the Checkout Service via a
Kafka topic. To instrument the Kafka client the ConsumerHandler implemented by
the developer has to be wrapped.

```go
handler := groupHandler{} // implements sarama.ConsumerGroupHandler
wrappedHandler := otelsarama.WrapConsumerGroupHandler(&handler)
```sh
dotnet publish "./AccountingService.csproj" --use-current-runtime -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
```
4 changes: 4 additions & 0 deletions static/refcache.json
Original file line number Diff line number Diff line change
Expand Up @@ -9347,6 +9347,10 @@
"StatusCode": 200,
"LastSeen": "2024-01-30T15:26:17.426269-05:00"
},
"https://www.nuget.org/packages/OpenTelemetry.AutoInstrumentation": {
"StatusCode": 200,
"LastSeen": "2024-05-13T07:12:48.012368334Z"
},
"https://www.nuget.org/packages/OpenTelemetry.Exporter.Console": {
"StatusCode": 200,
"LastSeen": "2024-01-30T16:04:59.787702-05:00"
Expand Down