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

Make overriding scope.name with logrecord.target configurable in OTLP Log Exporter #2102

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## vNext

- [2102](https://github.com/open-telemetry/opentelemetry-rust/pull/2102)
Added feature flag `populate-instrumentation-scope-from-target`, enabled by default.
- This will enable/disable corresponding flag for opentelemetry-proto.
- If flag is enabled `scope.name` is populated with `LogRecord.target`. scope.version and other `scope` fields are empty.
- If flag is disabled, `scope` is populated from opentelemetry-sdk's `InstrumentatonLibrary` - this includes name, version, url and attribute fields.

## v0.25.0

- Update `opentelemetry` dependency version to 0.25
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "opentelemetry-proto/
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics", "opentelemetry-proto/metrics"]
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "opentelemetry-proto/logs"]
populate-logs-event-name = ["opentelemetry-proto/populate-logs-event-name"]
populate-instrumentation-scope-from-target = ["opentelemetry-proto/populate-instrumentation-scope-from-target"]

# add ons
serialize = ["serde", "serde_json"]

default = ["grpc-tonic", "trace", "metrics", "logs"]
default = ["grpc-tonic", "trace", "metrics", "logs", "populate-instrumentation-scope-from-target"]

# grpc using tonic
grpc-tonic = ["tonic", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic"]
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-proto/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## vNext

- Fix JSON serialization of `metrics::Exemplar` and `trace::span::Link` [#2069](https://github.com/open-telemetry/opentelemetry-rust/pull/2069)
- [2102](https://github.com/open-telemetry/opentelemetry-rust/pull/2102)
Added feature flag `populate-instrumentation-scope-from-target`, enabled by default.
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/open-telemetry/opentelemetry-specification/issues/4154
I am wondering if we should offer this feature flag at all, given the target should be populated as scope always. The appender-name and version can be attributes on the scope. Need to follow the above spec issue before closely.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. We can instead have a feature flag to populate the appender-name/version as attributes, and keep target as scope as we do currently.

Copy link
Member

Choose a reason for hiding this comment

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

I think that could work, we need to wait for the spec issue to get resolved. For now, we can continue to keep target as scope. what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we can close this PR and make a decision once the spec issue is resolved

- If flag is enabled `scope.name` is populated with `LogRecord.target`. scope.version and other `scope` fields are empty.
- If flag is disabled, `scope` is populated from opentelemetry-sdk's `InstrumentatonLibrary` - this includes name, version, url and attribute fields.

## v0.25.0
- Update `opentelemetry` dependency version to 0.25
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ path = "tests/json_serde.rs"

[features]
default = ["full"]
full = ["gen-tonic", "trace", "logs", "metrics", "zpages", "with-serde"]
full = ["gen-tonic", "trace", "logs", "metrics", "zpages", "with-serde", "populate-instrumentation-scope-from-target"]

# crates used to generate rs files
gen-tonic = ["gen-tonic-messages", "tonic/transport"]
Expand All @@ -47,6 +47,7 @@ testing = ["opentelemetry/testing"]
with-schemars = ["schemars"]
with-serde = ["serde", "hex"]
populate-logs-event-name = []
populate-instrumentation-scope-from-target = []

[dependencies]
tonic = { workspace = true, optional = true, features = ["codegen", "prost"] }
Expand Down
24 changes: 18 additions & 6 deletions opentelemetry-proto/src/transform/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@
.clone()
.map(Into::into)
.unwrap_or_default(),
scope: Some((instrumentation, log_record.target.clone()).into()),
scope: if cfg!(feature = "populate-instrumentation-scope-from-target") {
Some((instrumentation, log_record.target.clone()).into())

Check warning on line 174 in opentelemetry-proto/src/transform/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/logs.rs#L173-L174

Added lines #L173 - L174 were not covered by tests
} else {
Some((instrumentation, None).into())

Check warning on line 176 in opentelemetry-proto/src/transform/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/logs.rs#L176

Added line #L176 was not covered by tests
},
log_records: vec![log_record.into()],
}],
}
Expand All @@ -192,10 +196,14 @@
)>,
>,
(log_record, instrumentation)| {
let key = log_record
.target
.clone()
.unwrap_or_else(|| Cow::Owned(instrumentation.name.clone().into_owned()));
let key = if cfg!(feature = "populate-instrumentation-scope-from-target") {
log_record
.target
.clone()
.unwrap_or_else(|| Cow::Owned(instrumentation.name.clone().into_owned()))
} else {
Cow::Owned(instrumentation.name.clone().into_owned())

Check warning on line 205 in opentelemetry-proto/src/transform/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/logs.rs#L205

Added line #L205 was not covered by tests
};
scope_map
.entry(key)
.or_default()
Expand All @@ -209,7 +217,11 @@
.map(|(key, log_data)| ScopeLogs {
scope: Some(InstrumentationScope::from((
log_data.first().unwrap().1,
Some(key.into_owned().into()),
if cfg!(feature = "populate-instrumentation-scope-from-target") {
Some(key.into_owned().into())
} else {
None

Check warning on line 223 in opentelemetry-proto/src/transform/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/logs.rs#L223

Added line #L223 was not covered by tests
},
))),
schema_url: resource.schema_url.clone().unwrap_or_default(),
log_records: log_data
Expand Down
Loading