Skip to content

Commit 6df2280

Browse files
authored
Merge branch 'main' into 168-otlp-span-exporter-env-cfg
2 parents 658740d + 14f6e00 commit 6df2280

File tree

40 files changed

+1947
-1206
lines changed

40 files changed

+1947
-1206
lines changed

.github/workflows/ci.yml

+7-12
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ jobs:
2323
- name: Test
2424
run: ./scripts/test.sh
2525
lint:
26-
strategy:
27-
matrix:
28-
rust: [stable, beta]
2926
runs-on: ubuntu-latest
3027
steps:
3128
- uses: actions/checkout@v1
3229
with:
3330
submodules: true
3431
- uses: actions-rs/toolchain@v1
3532
with:
36-
toolchain: ${{ matrix.rust }}
33+
toolchain: stable
3734
components: rustfmt
3835
profile: minimal
3936
- uses: arduino/setup-protoc@v1
37+
- uses: actions-rs/cargo@v1
38+
with:
39+
command: fmt
40+
args: --all -- --check
4041
- name: Lint
4142
run: ./scripts/lint.sh
4243
msrv:
@@ -55,7 +56,7 @@ jobs:
5556
cargo test --verbose --manifest-path=opentelemetry/Cargo.toml --features trace,metrics,serialize,tokio-support,serde,testing &&
5657
cargo test --manifest-path=opentelemetry-jaeger/Cargo.toml &&
5758
cargo test --manifest-path=opentelemetry-zipkin/Cargo.toml
58-
meta:
59+
coverage:
5960
continue-on-error: true
6061
runs-on: ubuntu-latest
6162
steps:
@@ -65,21 +66,15 @@ jobs:
6566
- uses: actions-rs/toolchain@v1
6667
with:
6768
toolchain: nightly
68-
components: rustfmt, clippy
6969
override: true
7070
- uses: arduino/setup-protoc@v1
7171
- uses: actions-rs/cargo@v1
7272
with:
7373
command: test
74-
args: -p opentelemetry --all-features --no-fail-fast
74+
args: -p opentelemetry -p opentelemetry-jaeger -p opentelemetry-zipkin -p opentelemetry-datadog -p opentelemetry-aws --all-features --no-fail-fast
7575
env:
7676
CARGO_INCREMENTAL: '0'
7777
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
7878
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
7979
- uses: actions-rs/[email protected]
8080
- uses: codecov/codecov-action@v1
81-
- run: cargo fmt -- --check
82-
- uses: actions-rs/clippy-check@v1
83-
with:
84-
token: ${{ secrets.GITHUB_TOKEN }}
85-
args: --all-features --workspace

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
members = [
33
"opentelemetry",
44
"opentelemetry-contrib",
5+
"opentelemetry-datadog",
56
"opentelemetry-http",
67
"opentelemetry-jaeger",
78
"opentelemetry-otlp",
89
"opentelemetry-prometheus",
10+
"opentelemetry-aws",
911
"opentelemetry-semantic-conventions",
1012
"opentelemetry-zipkin",
1113
"examples/actix-http",
@@ -16,6 +18,7 @@ members = [
1618
"examples/basic",
1719
"examples/basic-otlp",
1820
"examples/datadog",
21+
"examples/external-otlp-tonic-tokio",
1922
"examples/grpc",
2023
"examples/http",
2124
"examples/tracing-grpc",

examples/aws-xray/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ path = "src/client.rs"
1717
hyper = { version = "0.14", features = ["full"] }
1818
tokio = { version = "1.0", features = ["full"] }
1919
opentelemetry = { path = "../../opentelemetry" }
20-
opentelemetry-contrib = { path = "../../opentelemetry-contrib", features = ["aws-xray"] }
20+
opentelemetry-aws = { path = "../../opentelemetry-aws", features = ["trace"] }
2121
opentelemetry-http = { path = "../../opentelemetry-http" }

examples/aws-xray/src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use opentelemetry::{
66
trace::{TraceContextExt, Tracer},
77
Context, KeyValue,
88
};
9-
use opentelemetry_contrib::trace::propagator::XrayPropagator;
9+
use opentelemetry_aws::XrayPropagator;
1010
use opentelemetry_http::HeaderInjector;
1111

1212
fn init_tracer() -> (sdktrace::Tracer, stdout::Uninstall) {

examples/aws-xray/src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use opentelemetry::{
66
sdk::trace as sdktrace,
77
trace::{Span, Tracer},
88
};
9-
use opentelemetry_contrib::trace::propagator::XrayPropagator;
9+
use opentelemetry_aws::XrayPropagator;
1010
use opentelemetry_http::HeaderExtractor;
1111
use std::{convert::Infallible, net::SocketAddr};
1212

examples/datadog/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ edition = "2018"
55

66
[dependencies]
77
opentelemetry = { path = "../../opentelemetry" }
8-
opentelemetry-contrib = { path = "../../opentelemetry-contrib", features = ["datadog", "reqwest-blocking-client"] }
8+
opentelemetry-datadog = { path = "../../opentelemetry-datadog", features = ["reqwest-blocking-client"] }

examples/datadog/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use opentelemetry::{
33
trace::{Span, TraceContextExt, Tracer},
44
Key,
55
};
6-
use opentelemetry_contrib::trace::exporter::datadog::{new_pipeline, ApiVersion};
6+
use opentelemetry_datadog::{new_pipeline, ApiVersion};
77
use std::thread;
88
use std::time::Duration;
99

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "external-otlp-tonic-tokio"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
futures = "0.3"
8+
opentelemetry = { path = "../../opentelemetry", features = [
9+
"tokio-support",
10+
"metrics",
11+
"serialize"
12+
] }
13+
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = [
14+
"tonic",
15+
"tls",
16+
"tls-roots",
17+
] }
18+
serde_json = "1.0"
19+
tokio = { version = "1.0", features = ["full"] }
20+
tonic = "0.4.0"
21+
url = "2.2.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# External OTLP collector with tonic and tokio with TLS
2+
3+
This example shows basic span, and exports to OTLP enabled collectors, like honeycomb, lightstep and other services.
4+
As these services all reside outside your own infrastructure, they require TLS for encryption to ensure your data safety.
5+
With this example, you can export to any service that supports OTLP by using environment variables.
6+
The following example exports data to Honeycomb:
7+
8+
```shell
9+
OTLP_TONIC_ENDPOINT=https://api.honeycomb.io:443 \
10+
OTLP_TONIC_X_HONEYCOMB_TEAM=token \
11+
OTLP_TONIC_X_HONEYCOMB_DATASET=dataset \'
12+
cargo run --bin external-otlp-tonic-tokio
13+
```
14+
15+
The only required variable is `OTLP_TONIC_ENDPOINT` and any other variable that beggins with the prefix `OTLP_TONIC_` will be sent as headers
16+
e.g.: `OTLP_TONIC_X_HONEYCOMB_TEAM` becomes `x-honeycomb-team` and `OTLP_TONIC_X_HONEYCOMB_DATASET` becomes `x-honeycomb-dataset`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//! This should show how to connect to a third party collector like
2+
//! honeycomb or lightstep using tonic with tls and using tokio as reactor.
3+
//! To run this you have to specify a few environment variables like in the example:
4+
//! ```shell
5+
//! OTLP_TONIC_ENDPOINT=https://api.honeycomb.io:443 \
6+
//! OTLP_TONIC_X_HONEYCOMB_TEAM=token \
7+
//! OTLP_TONIC_X_HONEYCOMB_DATASET=dataset \'
8+
//! cargo run --bin external-otlp-tonic-tokio
9+
//! ```
10+
use opentelemetry::trace::TraceError;
11+
use opentelemetry::{global, sdk::trace as sdktrace};
12+
use opentelemetry::{
13+
trace::{TraceContextExt, Tracer},
14+
Key,
15+
};
16+
use tonic::{
17+
metadata::{MetadataKey, MetadataMap},
18+
transport::ClientTlsConfig,
19+
};
20+
use url::Url;
21+
22+
use std::{env::vars, str::FromStr, time::Duration};
23+
use std::{
24+
env::{remove_var, var},
25+
error::Error,
26+
};
27+
28+
// Use the variables to try and export the example to any external collector that accepts otlp
29+
// like: oltp itself, honeycomb or lightstep
30+
const ENDPOINT: &str = "OTLP_TONIC_ENDPOINT";
31+
const HEADER_PREFIX: &str = "OTLP_TONIC_";
32+
33+
fn init_tracer() -> Result<(sdktrace::Tracer, opentelemetry_otlp::Uninstall), TraceError> {
34+
let endpoint = var(ENDPOINT).unwrap_or_else(|_| {
35+
panic!(
36+
"You must specify and endpoint to connect to with the variable {:?}.",
37+
ENDPOINT
38+
)
39+
});
40+
let endpoint = Url::parse(&endpoint).expect("endpoint is not a valid url");
41+
remove_var(ENDPOINT);
42+
let mut metadata = MetadataMap::new();
43+
for (key, value) in vars()
44+
.filter(|(name, _)| name.starts_with(HEADER_PREFIX))
45+
.map(|(name, value)| {
46+
let header_name = name
47+
.strip_prefix(HEADER_PREFIX)
48+
.map(|h| h.replace("_", "-"))
49+
.map(|h| h.to_ascii_lowercase())
50+
.unwrap();
51+
(header_name, value)
52+
})
53+
{
54+
metadata.insert(MetadataKey::from_str(&key).unwrap(), value.parse().unwrap());
55+
}
56+
57+
opentelemetry_otlp::new_pipeline()
58+
.with_endpoint(endpoint.as_str())
59+
.with_metadata(dbg!(metadata))
60+
.with_tls_config(
61+
ClientTlsConfig::new().domain_name(
62+
endpoint
63+
.host_str()
64+
.expect("the specified endpoint should have a valid host"),
65+
),
66+
)
67+
.install()
68+
}
69+
70+
const LEMONS_KEY: Key = Key::from_static_str("ex.com/lemons");
71+
const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another");
72+
73+
#[tokio::main]
74+
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
75+
let (_, _guard) = init_tracer()?;
76+
77+
let tracer = global::tracer("ex.com/basic");
78+
79+
tracer.in_span("operation", |cx| {
80+
let span = cx.span();
81+
span.add_event(
82+
"Nice operation!".to_string(),
83+
vec![Key::new("bogons").i64(100)],
84+
);
85+
span.set_attribute(ANOTHER_KEY.string("yes"));
86+
87+
tracer.in_span("Sub operation...", |cx| {
88+
let span = cx.span();
89+
span.set_attribute(LEMONS_KEY.string("five"));
90+
91+
span.add_event("Sub span event".to_string(), vec![]);
92+
});
93+
});
94+
95+
// wait for 1 minutes so that we could see metrics being pushed via OTLP every 10 seconds.
96+
tokio::time::sleep(Duration::from_secs(60)).await;
97+
98+
Ok(())
99+
}

opentelemetry-aws/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## v0.1.0
2+
3+
### Added
4+
5+
- AWS XRay propagator

opentelemetry-aws/CODEOWNERS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code owners file.
2+
# This file controls who is tagged for review for any given pull request.
3+
4+
# For anything not explicitly taken by someone else:
5+
* @open-telemetry/rust-approvers

opentelemetry-aws/Cargo.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "opentelemetry-aws"
3+
version = "0.1.0"
4+
authors = ["OpenTelemetry Authors <[email protected]>"]
5+
description = "AWS exporters and propagators for OpenTelemetry"
6+
homepage = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-aws"
7+
repository = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-aws"
8+
readme = "README.md"
9+
categories = [
10+
"development-tools::debugging",
11+
"development-tools::profiling",
12+
]
13+
keywords = ["opentelemetry", "tracing"]
14+
license = "Apache-2.0"
15+
edition = "2018"
16+
17+
[package.metadata.docs.rs]
18+
all-features = true
19+
rustdoc-args = ["--cfg", "docsrs"]
20+
21+
[features]
22+
default = ["trace"]
23+
trace = ["opentelemetry/trace"]
24+
25+
[dependencies]
26+
opentelemetry = { version = "0.12", path = "../opentelemetry", features = ["trace"] }
27+
lazy_static = "1.4"
28+
29+
[dev-dependencies]
30+
opentelemetry = { path = "../opentelemetry", features = ["trace", "testing"] }

0 commit comments

Comments
 (0)