-
Notifications
You must be signed in to change notification settings - Fork 454
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
[DRAFT] Add Custom Thread-Based Runtime for OpenTelemetry batch Processing #2390
Draft
lalitb
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
lalitb:dedicated-thread-runtime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+609
−1
Draft
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "logs-batch" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
publish = false | ||
|
||
[dependencies] | ||
opentelemetry = { path = "../../opentelemetry", features = ["logs"] } | ||
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["logs"] } | ||
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["logs"]} | ||
opentelemetry-appender-log = { path = "../../opentelemetry-appender-log", default-features = false} | ||
opentelemetry-semantic-conventions = { path = "../../opentelemetry-semantic-conventions" } | ||
log = { workspace = true } | ||
serde_json = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# OpenTelemetry Log Appender for log - Example using Batch Log Processor and thread runtime | ||
|
||
This example shows how to use the opentelemetry-appender-log crate, which is a | ||
[logging | ||
appender](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#log-appender--bridge) | ||
that bridges logs from the [log crate](https://docs.rs/log/latest/log/) to | ||
OpenTelemetry. The example setups a LoggerProvider with stdout exporter, so logs | ||
are emitted to stdout. | ||
|
||
## Usage | ||
|
||
Run the following, and Logs emitted using [log](https://docs.rs/log/latest/log/) | ||
will be written out to stdout. | ||
|
||
```shell | ||
cargo run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use log::{error, Level}; | ||
use opentelemetry::KeyValue; | ||
use opentelemetry_appender_log::OpenTelemetryLogBridge; | ||
use opentelemetry_sdk::logs::LoggerProvider; | ||
use opentelemetry_sdk::thread_runtime::CustomThreadRuntime; | ||
use opentelemetry_sdk::Resource; | ||
use opentelemetry_semantic_conventions::resource::SERVICE_NAME; | ||
|
||
fn main() { | ||
// Setup LoggerProvider with a stdout exporter | ||
let exporter = opentelemetry_stdout::LogExporter::default(); | ||
let runtime = CustomThreadRuntime::new(2, 5); // 1 worker thread | ||
let logger_provider = LoggerProvider::builder() | ||
.with_resource(Resource::new([KeyValue::new( | ||
SERVICE_NAME, | ||
"logs-basic-example", | ||
)])) | ||
.with_batch_exporter(exporter, runtime) | ||
.build(); | ||
|
||
// Setup Log Appender for the log crate. | ||
let otel_log_appender = OpenTelemetryLogBridge::new(&logger_provider); | ||
log::set_boxed_logger(Box::new(otel_log_appender)).unwrap(); | ||
log::set_max_level(Level::Error.to_level_filter()); | ||
|
||
// Emit logs using macros from the log crate. | ||
// These logs gets piped through OpenTelemetry bridge and gets exported to stdout. | ||
// 10 error events | ||
for i in 0..10000 { | ||
error!(target: "my-target", "hello from {}. My price is {} at itr {}", "apple", 2.99, i); | ||
//sleep 1 sec every 100 secs | ||
if i % 10 == 0 { | ||
std::thread::sleep(std::time::Duration::from_secs(1)); | ||
} | ||
} | ||
println!("Flushing logs explicitly before exiting.."); | ||
logger_provider.force_flush(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is for marshalling async events from
futures
runtime totokio
/async-std
. Its dependency can be eliminated by integrating the necessary code from this package, as it appears to be relatively small.