Skip to content

Commit

Permalink
Merge branch 'main' into opentelemetry-journald-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 4, 2024
2 parents 939a39f + 7c131c4 commit 7c8d75c
Show file tree
Hide file tree
Showing 78 changed files with 1,418 additions and 1,278 deletions.
17 changes: 7 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ members = [
"opentelemetry-*",
"examples/*",
]
exclude = [
"opentelemetry-dynatrace",
]
resolver = "2"

[profile.bench]
Expand All @@ -15,10 +12,10 @@ resolver = "2"
debug = 1

[workspace.dependencies]
opentelemetry = "0.23"
opentelemetry-appender-tracing = "0.4"
opentelemetry-http = "0.12"
opentelemetry-proto = { version = "0.6", default-features = false }
opentelemetry_sdk = { version = "0.23", default-features = false }
opentelemetry-stdout = "0.4"
opentelemetry-semantic-conventions = "0.15"
opentelemetry = "0.26"
opentelemetry-appender-tracing = "0.26"
opentelemetry-http = "0.26"
opentelemetry-proto = { version = "0.26", default-features = false }
opentelemetry_sdk = { version = "0.26", default-features = false }
opentelemetry-stdout = "0.26"
opentelemetry-semantic-conventions = { version = "0.26", features = ["semconv_experimental"] }
4 changes: 3 additions & 1 deletion examples/traceresponse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ path = "src/client.rs"
doc = false

[dependencies]
hyper = { version = "0.14", features = ["full"] }
http-body-util = { version="0.1" }
hyper = { version = "1.4.1", features = ["full"] }
hyper-util = {version = "0.1", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
opentelemetry = { workspace = true }
opentelemetry_sdk = { workspace = true }
Expand Down
11 changes: 7 additions & 4 deletions examples/traceresponse/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use http_body_util::Full;
use hyper::http::HeaderValue;
use hyper::{body::Body, Client};
use hyper_util::{client::legacy::Client, rt::TokioExecutor};
use opentelemetry::{
global,
propagation::TextMapPropagator,
trace::{SpanKind, TraceContextExt, Tracer},
Context, KeyValue,
};
use opentelemetry_contrib::trace::propagator::trace_context_response::TraceContextResponsePropagator;
use opentelemetry_http::{HeaderExtractor, HeaderInjector};
use opentelemetry_http::{Bytes, HeaderExtractor, HeaderInjector};
use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::TracerProvider};
use opentelemetry_stdout::SpanExporter;

Expand All @@ -27,7 +28,7 @@ fn init_tracer() {
async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
init_tracer();

let client = Client::new();
let client = Client::builder(TokioExecutor::new()).build_http();
let tracer = global::tracer("example/client");
let span = tracer
.span_builder("say hello")
Expand All @@ -39,7 +40,9 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sy
global::get_text_map_propagator(|propagator| {
propagator.inject_context(&cx, &mut HeaderInjector(req.headers_mut().unwrap()))
});
let res = client.request(req.body(Body::from("Hello!"))?).await?;
let res = client
.request(req.body(Full::new(Bytes::from("Hello!")))?)
.await?;

let response_propagator: &dyn TextMapPropagator = &TraceContextResponsePropagator::new();

Expand Down
37 changes: 22 additions & 15 deletions examples/traceresponse/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
use http_body_util::{combinators::BoxBody, BodyExt, Full};
use hyper::{body::Incoming, service::service_fn, Request, Response};
use hyper_util::rt::{TokioExecutor, TokioIo};
use opentelemetry::{
global,
propagation::TextMapPropagator,
trace::{SpanKind, TraceContextExt, Tracer},
Context,
};
use opentelemetry_contrib::trace::propagator::trace_context_response::TraceContextResponsePropagator;
use opentelemetry_http::{HeaderExtractor, HeaderInjector};
use opentelemetry_http::{Bytes, HeaderExtractor, HeaderInjector};
use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::TracerProvider};
use opentelemetry_stdout::SpanExporter;
use std::{convert::Infallible, net::SocketAddr};
use tokio::net::TcpListener;

async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> {
async fn handle(
req: Request<Incoming>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, Infallible> {
let parent_cx = global::get_text_map_propagator(|propagator| {
propagator.extract(&HeaderExtractor(req.headers()))
});
Expand All @@ -30,8 +32,11 @@ async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> {

cx.span().add_event("handling this...", Vec::new());

let mut res = Response::new("Hello, World!".into());

let mut res = Response::new(
Full::new(Bytes::from_static(b"Server is up and running!"))
.map_err(|err| match err {})
.boxed(),
);
let response_propagator: &dyn TextMapPropagator = &TraceContextResponsePropagator::new();
response_propagator.inject_context(&cx, &mut HeaderInjector(res.headers_mut()));

Expand All @@ -53,15 +58,17 @@ fn init_tracer() {

#[tokio::main]
async fn main() {
use hyper_util::server::conn::auto::Builder;
init_tracer();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let listener = TcpListener::bind(addr).await.unwrap();

let make_svc = make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(handle)) });

let server = Server::bind(&addr).serve(make_svc);

println!("Listening on {addr}");
if let Err(e) = server.await {
eprintln!("server error: {e}");
while let Ok((stream, _addr)) = listener.accept().await {
if let Err(err) = Builder::new(TokioExecutor::new())
.serve_connection(TokioIo::new(stream), service_fn(handle))
.await
{
eprintln!("{err}");
}
}
}
17 changes: 16 additions & 1 deletion opentelemetry-aws/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Changelog

## vNext
## v0.13.0

### Added

- `LambdaResourceDetector` has been added to the crate to detect AWS Lambda attributes. To enable it in your code, use the feature `detector-aws-lambda`.

### Changed

- Bump opentelemetry and opentelemetry_sdk versions to 0.25.0

## v0.12.0

- Bump opentelemetry and opentelemetry_sdk versions to 0.24.0
- Update hyper to 1.4.1

## v0.11.0

### Changed

Expand Down
7 changes: 5 additions & 2 deletions opentelemetry-aws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentelemetry-aws"
version = "0.11.0"
version = "0.13.0"
description = "AWS exporters and propagators for OpenTelemetry"
homepage = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-aws"
repository = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-aws"
Expand All @@ -21,15 +21,18 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = ["trace"]
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace"]
detector-aws-lambda = ["dep:opentelemetry-semantic-conventions"]

[dependencies]
once_cell = "1.12"
opentelemetry = { workspace = true }
opentelemetry_sdk = { workspace = true, optional = true }
opentelemetry-semantic-conventions = { workspace = true, optional = true }

[dev-dependencies]
opentelemetry_sdk = { workspace = true, features = ["testing"] }
opentelemetry-http = { workspace = true }
opentelemetry-stdout = { workspace = true, features = ["trace"] }
hyper = { version = "0.14" }
hyper = { version = "1.4.1" }
tokio = { version = "1.0", features = ["macros", "rt"] }
sealed_test = "1.1.0"
95 changes: 95 additions & 0 deletions opentelemetry-aws/src/detector/lambda.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use opentelemetry::KeyValue;
use opentelemetry_sdk::resource::ResourceDetector;
use opentelemetry_sdk::Resource;
use opentelemetry_semantic_conventions as semconv;
use std::env;
use std::time::Duration;

// For a complete list of reserved environment variables in Lambda, see:
// https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
const AWS_LAMBDA_FUNCTION_NAME_ENV_VAR: &str = "AWS_LAMBDA_FUNCTION_NAME";
const AWS_REGION_ENV_VAR: &str = "AWS_REGION";
const AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR: &str = "AWS_LAMBDA_FUNCTION_VERSION";
const AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR: &str = "AWS_LAMBDA_LOG_STREAM_NAME";
const AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR: &str = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE";

/// Resource detector that collects resource information from AWS Lambda environment.
pub struct LambdaResourceDetector;

impl ResourceDetector for LambdaResourceDetector {
fn detect(&self, _: Duration) -> Resource {
let lambda_name = env::var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR).unwrap_or_default();
// If no lambda name is provided, it means that
// we're not on a Lambda environment, so we return empty resource.
if lambda_name.is_empty() {
return Resource::empty();
}

let aws_region = env::var(AWS_REGION_ENV_VAR).unwrap_or_default();
let function_version = env::var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR).unwrap_or_default();
let function_memory_limit = env::var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR).unwrap_or_default();
// Instance attributes corresponds to the log stream name for AWS Lambda;
// See the FaaS resource specification for more details.
let instance = env::var(AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR).unwrap_or_default();

let attributes = [
KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"),
KeyValue::new(semconv::resource::CLOUD_REGION, aws_region),
KeyValue::new(semconv::resource::FAAS_INSTANCE, instance),
KeyValue::new(semconv::resource::FAAS_NAME, lambda_name),
KeyValue::new(semconv::resource::FAAS_VERSION, function_version),
KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, function_memory_limit),
];

Resource::new(attributes)
}
}

#[cfg(test)]
mod tests {
use super::*;
use sealed_test::prelude::*;
use std::env::{remove_var, set_var};

#[sealed_test]
fn test_aws_lambda_detector() {
set_var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR, "my-lambda-function");
set_var(AWS_REGION_ENV_VAR, "eu-west-3");
set_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR, "$LATEST");
set_var(
AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR,
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
);
set_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR, "128");

let expected = Resource::new([
KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"),
KeyValue::new(semconv::resource::CLOUD_REGION, "eu-west-3"),
KeyValue::new(
semconv::resource::FAAS_INSTANCE,
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
),
KeyValue::new(semconv::resource::FAAS_NAME, "my-lambda-function"),
KeyValue::new(semconv::resource::FAAS_VERSION, "$LATEST"),
KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, "128"),
]);

let detector = LambdaResourceDetector {};
let got = detector.detect(Duration::from_secs(0));

assert_eq!(expected, got);

remove_var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR);
remove_var(AWS_REGION_ENV_VAR);
remove_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR);
remove_var(AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR);
remove_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR);
}

#[sealed_test]
fn test_aws_lambda_detector_returns_empty_if_no_lambda_environment() {
let detector = LambdaResourceDetector {};
let got = detector.detect(Duration::from_secs(0));
assert_eq!(Resource::empty(), got);
}
}
4 changes: 4 additions & 0 deletions opentelemetry-aws/src/detector/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(feature = "detector-aws-lambda")]
mod lambda;
#[cfg(feature = "detector-aws-lambda")]
pub use lambda::LambdaResourceDetector;
1 change: 1 addition & 0 deletions opentelemetry-aws/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod detector;
pub mod trace;
16 changes: 16 additions & 0 deletions opentelemetry-contrib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

## vNext

## v0.17.0

### Changed

- Bump opentelemetry and opentelemetry_sdk versions to 0.25
- Bump opentelemetry-semantic-conventions version to 0.25

## v0.16.0

### Changed

- Bump opentelemetry and opentelemetry_sdk versions to 0.24.0
- Bump opentelemetry-semantic-conventions version to 0.16

## v0.15.0

### Changed

- Bump opentelemetry and opentelemetry_sdk versions to 0.23
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-contrib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentelemetry-contrib"
version = "0.15.0"
version = "0.17.0"
description = "Rust contrib repo for OpenTelemetry"
homepage = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-contrib"
repository = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-contrib"
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-contrib/benches/new_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use opentelemetry_contrib::trace::{
};
use opentelemetry_sdk::{
export::trace::{ExportResult, SpanData, SpanExporter},
trace::{config, Sampler, TracerProvider},
trace::{Config, Sampler, TracerProvider},
};
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Display for Environment {

fn parent_sampled_tracer(inner_sampler: Sampler) -> (TracerProvider, BoxedTracer) {
let provider = TracerProvider::builder()
.with_config(config().with_sampler(Sampler::ParentBased(Box::new(inner_sampler))))
.with_config(Config::default().with_sampler(Sampler::ParentBased(Box::new(inner_sampler))))
.with_simple_exporter(NoopExporter)
.build();
let tracer = provider.tracer(module_path!());
Expand Down
14 changes: 13 additions & 1 deletion opentelemetry-datadog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## vNext

## v0.13.0

### Changed

- Bump opentelemetry and opentelemetry_sdk version to 0.25

## v0.12.0

### Changed

- Bump opentelemetry and opentelemetry_sdk version to 0.24
- Bump hyper to version 1

## v0.10.0

### Added
Expand All @@ -17,7 +30,6 @@
- allow send all traces to `datadog-agent` with `agent-sampling` feature.
- allow `datadog-agent` generate metrics from spans for [APM](https://docs.datadoghq.com/tracing/metrics/).


## v0.9.0

### Changed
Expand Down
Loading

0 comments on commit 7c8d75c

Please sign in to comment.