Skip to content

Commit

Permalink
Merge branch 'main' into 168-otlp-span-exporter-env-cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher authored Feb 11, 2021
2 parents 658740d + 14f6e00 commit 6df2280
Show file tree
Hide file tree
Showing 40 changed files with 1,947 additions and 1,206 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ jobs:
- name: Test
run: ./scripts/test.sh
lint:
strategy:
matrix:
rust: [stable, beta]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
toolchain: stable
components: rustfmt
profile: minimal
- uses: arduino/setup-protoc@v1
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Lint
run: ./scripts/lint.sh
msrv:
Expand All @@ -55,7 +56,7 @@ jobs:
cargo test --verbose --manifest-path=opentelemetry/Cargo.toml --features trace,metrics,serialize,tokio-support,serde,testing &&
cargo test --manifest-path=opentelemetry-jaeger/Cargo.toml &&
cargo test --manifest-path=opentelemetry-zipkin/Cargo.toml
meta:
coverage:
continue-on-error: true
runs-on: ubuntu-latest
steps:
Expand All @@ -65,21 +66,15 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt, clippy
override: true
- uses: arduino/setup-protoc@v1
- uses: actions-rs/cargo@v1
with:
command: test
args: -p opentelemetry --all-features --no-fail-fast
args: -p opentelemetry -p opentelemetry-jaeger -p opentelemetry-zipkin -p opentelemetry-datadog -p opentelemetry-aws --all-features --no-fail-fast
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
- uses: actions-rs/[email protected]
- uses: codecov/codecov-action@v1
- run: cargo fmt -- --check
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --workspace
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
members = [
"opentelemetry",
"opentelemetry-contrib",
"opentelemetry-datadog",
"opentelemetry-http",
"opentelemetry-jaeger",
"opentelemetry-otlp",
"opentelemetry-prometheus",
"opentelemetry-aws",
"opentelemetry-semantic-conventions",
"opentelemetry-zipkin",
"examples/actix-http",
Expand All @@ -16,6 +18,7 @@ members = [
"examples/basic",
"examples/basic-otlp",
"examples/datadog",
"examples/external-otlp-tonic-tokio",
"examples/grpc",
"examples/http",
"examples/tracing-grpc",
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-xray/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ path = "src/client.rs"
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
opentelemetry = { path = "../../opentelemetry" }
opentelemetry-contrib = { path = "../../opentelemetry-contrib", features = ["aws-xray"] }
opentelemetry-aws = { path = "../../opentelemetry-aws", features = ["trace"] }
opentelemetry-http = { path = "../../opentelemetry-http" }
2 changes: 1 addition & 1 deletion examples/aws-xray/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use opentelemetry::{
trace::{TraceContextExt, Tracer},
Context, KeyValue,
};
use opentelemetry_contrib::trace::propagator::XrayPropagator;
use opentelemetry_aws::XrayPropagator;
use opentelemetry_http::HeaderInjector;

fn init_tracer() -> (sdktrace::Tracer, stdout::Uninstall) {
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-xray/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use opentelemetry::{
sdk::trace as sdktrace,
trace::{Span, Tracer},
};
use opentelemetry_contrib::trace::propagator::XrayPropagator;
use opentelemetry_aws::XrayPropagator;
use opentelemetry_http::HeaderExtractor;
use std::{convert::Infallible, net::SocketAddr};

Expand Down
2 changes: 1 addition & 1 deletion examples/datadog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ edition = "2018"

[dependencies]
opentelemetry = { path = "../../opentelemetry" }
opentelemetry-contrib = { path = "../../opentelemetry-contrib", features = ["datadog", "reqwest-blocking-client"] }
opentelemetry-datadog = { path = "../../opentelemetry-datadog", features = ["reqwest-blocking-client"] }
2 changes: 1 addition & 1 deletion examples/datadog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use opentelemetry::{
trace::{Span, TraceContextExt, Tracer},
Key,
};
use opentelemetry_contrib::trace::exporter::datadog::{new_pipeline, ApiVersion};
use opentelemetry_datadog::{new_pipeline, ApiVersion};
use std::thread;
use std::time::Duration;

Expand Down
21 changes: 21 additions & 0 deletions examples/external-otlp-tonic-tokio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "external-otlp-tonic-tokio"
version = "0.1.0"
edition = "2018"

[dependencies]
futures = "0.3"
opentelemetry = { path = "../../opentelemetry", features = [
"tokio-support",
"metrics",
"serialize"
] }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = [
"tonic",
"tls",
"tls-roots",
] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
tonic = "0.4.0"
url = "2.2.0"
16 changes: 16 additions & 0 deletions examples/external-otlp-tonic-tokio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# External OTLP collector with tonic and tokio with TLS

This example shows basic span, and exports to OTLP enabled collectors, like honeycomb, lightstep and other services.
As these services all reside outside your own infrastructure, they require TLS for encryption to ensure your data safety.
With this example, you can export to any service that supports OTLP by using environment variables.
The following example exports data to Honeycomb:

```shell
OTLP_TONIC_ENDPOINT=https://api.honeycomb.io:443 \
OTLP_TONIC_X_HONEYCOMB_TEAM=token \
OTLP_TONIC_X_HONEYCOMB_DATASET=dataset \'
cargo run --bin external-otlp-tonic-tokio
```

The only required variable is `OTLP_TONIC_ENDPOINT` and any other variable that beggins with the prefix `OTLP_TONIC_` will be sent as headers
e.g.: `OTLP_TONIC_X_HONEYCOMB_TEAM` becomes `x-honeycomb-team` and `OTLP_TONIC_X_HONEYCOMB_DATASET` becomes `x-honeycomb-dataset`.
99 changes: 99 additions & 0 deletions examples/external-otlp-tonic-tokio/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//! This should show how to connect to a third party collector like
//! honeycomb or lightstep using tonic with tls and using tokio as reactor.
//! To run this you have to specify a few environment variables like in the example:
//! ```shell
//! OTLP_TONIC_ENDPOINT=https://api.honeycomb.io:443 \
//! OTLP_TONIC_X_HONEYCOMB_TEAM=token \
//! OTLP_TONIC_X_HONEYCOMB_DATASET=dataset \'
//! cargo run --bin external-otlp-tonic-tokio
//! ```
use opentelemetry::trace::TraceError;
use opentelemetry::{global, sdk::trace as sdktrace};
use opentelemetry::{
trace::{TraceContextExt, Tracer},
Key,
};
use tonic::{
metadata::{MetadataKey, MetadataMap},
transport::ClientTlsConfig,
};
use url::Url;

use std::{env::vars, str::FromStr, time::Duration};
use std::{
env::{remove_var, var},
error::Error,
};

// Use the variables to try and export the example to any external collector that accepts otlp
// like: oltp itself, honeycomb or lightstep
const ENDPOINT: &str = "OTLP_TONIC_ENDPOINT";
const HEADER_PREFIX: &str = "OTLP_TONIC_";

fn init_tracer() -> Result<(sdktrace::Tracer, opentelemetry_otlp::Uninstall), TraceError> {
let endpoint = var(ENDPOINT).unwrap_or_else(|_| {
panic!(
"You must specify and endpoint to connect to with the variable {:?}.",
ENDPOINT
)
});
let endpoint = Url::parse(&endpoint).expect("endpoint is not a valid url");
remove_var(ENDPOINT);
let mut metadata = MetadataMap::new();
for (key, value) in vars()
.filter(|(name, _)| name.starts_with(HEADER_PREFIX))
.map(|(name, value)| {
let header_name = name
.strip_prefix(HEADER_PREFIX)
.map(|h| h.replace("_", "-"))
.map(|h| h.to_ascii_lowercase())
.unwrap();
(header_name, value)
})
{
metadata.insert(MetadataKey::from_str(&key).unwrap(), value.parse().unwrap());
}

opentelemetry_otlp::new_pipeline()
.with_endpoint(endpoint.as_str())
.with_metadata(dbg!(metadata))
.with_tls_config(
ClientTlsConfig::new().domain_name(
endpoint
.host_str()
.expect("the specified endpoint should have a valid host"),
),
)
.install()
}

const LEMONS_KEY: Key = Key::from_static_str("ex.com/lemons");
const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another");

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let (_, _guard) = init_tracer()?;

let tracer = global::tracer("ex.com/basic");

tracer.in_span("operation", |cx| {
let span = cx.span();
span.add_event(
"Nice operation!".to_string(),
vec![Key::new("bogons").i64(100)],
);
span.set_attribute(ANOTHER_KEY.string("yes"));

tracer.in_span("Sub operation...", |cx| {
let span = cx.span();
span.set_attribute(LEMONS_KEY.string("five"));

span.add_event("Sub span event".to_string(), vec![]);
});
});

// wait for 1 minutes so that we could see metrics being pushed via OTLP every 10 seconds.
tokio::time::sleep(Duration::from_secs(60)).await;

Ok(())
}
5 changes: 5 additions & 0 deletions opentelemetry-aws/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## v0.1.0

### Added

- AWS XRay propagator
5 changes: 5 additions & 0 deletions opentelemetry-aws/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Code owners file.
# This file controls who is tagged for review for any given pull request.

# For anything not explicitly taken by someone else:
* @open-telemetry/rust-approvers
30 changes: 30 additions & 0 deletions opentelemetry-aws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "opentelemetry-aws"
version = "0.1.0"
authors = ["OpenTelemetry Authors <[email protected]>"]
description = "AWS exporters and propagators for OpenTelemetry"
homepage = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-aws"
repository = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-aws"
readme = "README.md"
categories = [
"development-tools::debugging",
"development-tools::profiling",
]
keywords = ["opentelemetry", "tracing"]
license = "Apache-2.0"
edition = "2018"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["trace"]
trace = ["opentelemetry/trace"]

[dependencies]
opentelemetry = { version = "0.12", path = "../opentelemetry", features = ["trace"] }
lazy_static = "1.4"

[dev-dependencies]
opentelemetry = { path = "../opentelemetry", features = ["trace", "testing"] }
Loading

0 comments on commit 6df2280

Please sign in to comment.