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

Add feature for starting opentelemetry with tokio current thread runtime #28

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prima-tracing"
version = "0.3.0"
version = "0.3.1"
license = "MIT OR Apache-2.0"
readme = "README.md"
authors = ["Enrico Risa <[email protected]>"]
Expand All @@ -14,6 +14,7 @@ prima-logger = ["tracing-log"]
prima-telemetry = ["tracing-opentelemetry", "opentelemetry", "opentelemetry-zipkin"]
prima-logger-json = ["prima-logger"]
prima-logger-datadog = ["prima-logger-json", "opentelemetry", "tracing-opentelemetry"]
rt-tokio-current-thread = ["opentelemetry/rt-tokio-current-thread"]

[[example]]
name = "custom-json-subscriber"
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@

## Installation

Install from GitHub
Install from [crates.io](https://crates.io/crates/prima-tracing)

```toml
prima-tracing = { git="https://github.com/primait/prima_tracing.rs", branch="master" }
prima-tracing = "0.3.1"
```

## Cargo features

- `prima-logger-json` use JSON as output format
- `prima-logger-datadog` extends `prima-logger-json` output with [trace and span information](https://docs.datadoghq.com/tracing/connect_logs_and_traces/opentelemetry/) allowing Datadog to connect logs and traces
- `prima-logger-datadog` extends `prima-logger-json` output
with [trace and span information](https://docs.datadoghq.com/tracing/connect_logs_and_traces/opentelemetry/) allowing
Datadog to connect logs and traces
- `prima-telemetry` integrate opentelemetry with `opentelemetry-zipkin`
- `rt-tokio-current-thread` uses opentelemetry runtime implementation, which works with Tokio’s current thread runtime(
ex. `actix_web::main`). Without this feature the default uses Tokio’s multi thread runtime.

## Example

Expand Down Expand Up @@ -158,9 +162,11 @@ curl http://localhost:8081/check
Open the browser at <http://localhost:16686> to inspect the traced request

#### OpenTelemetry + JSON logger with Datadog correlation IDs

```sh
RUST_LOG=info cargo run --features=prima-logger-datadog,prima-telemetry --example datadog_json_logger
```

### Custom formatter

```sh
Expand Down
13 changes: 12 additions & 1 deletion src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
.as_ref()
.expect("Tracing config should be provided when the feature `prima-tracing` is enabled");

let runtime = {
#[cfg(feature = "rt-tokio-current-thread")]
{
opentelemetry::runtime::TokioCurrentThread
}
#[cfg(not(feature = "rt-tokio-current-thread"))]
{
opentelemetry::runtime::Tokio
}
};
Comment on lines +20 to +29
Copy link
Member

Choose a reason for hiding this comment

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

never saw scopes used like this!


opentelemetry_zipkin::new_pipeline()
.with_collector_endpoint(telemetry.collector_url.as_str())
.with_service_name(telemetry.service_name.as_str())
Expand All @@ -26,7 +37,7 @@ pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
config.env.clone(),
)])),
)
.install_batch(opentelemetry::runtime::Tokio)
.install_batch(runtime)
.expect("Failed to create the zipkin pipeline")
}

Expand Down