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

OTLP registry emitter #549

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

jerbly
Copy link
Contributor

@jerbly jerbly commented Jan 12, 2025

First iteration of the new command: registry emit. Emits a semantic convention registry as example spans to your OTLP receiver. This may be useful in testing/simulation scenarios. Defaults to http://localhost:4317 if the OpenTelemetry standard OTEL_EXPORTER_OTLP_ENDPOINT env var is unset.

With this command:

weaver registry emit

A single trace with all defined spans in the current Semantic Conventions are sent to the receiver:
image

Spans:

  • Emit all defined spans for the registry in a single trace.
  • Use standard OpenTelemetry libraries for real-world compatibility
  • Write tests using a custom Exporter
  • Generate examples from the resolved examples in the registry
  • Use the correct span_kind

A future PR will cover:

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.6%. Comparing base (d616ff9) to head (9a41168).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #549   +/-   ##
=====================================
  Coverage   74.6%   74.6%           
=====================================
  Files         51      51           
  Lines       3965    3965           
=====================================
+ Hits        2958    2959    +1     
+ Misses      1007    1006    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jerbly jerbly marked this pull request as ready for review January 18, 2025 02:59
@jerbly jerbly requested a review from a team as a code owner January 18, 2025 02:59
Copy link
Contributor

@lquerel lquerel left a comment

Choose a reason for hiding this comment

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

Overall, I really like the idea of having a semconv registry-driven generation of OTLP signals! It opens up a lot of interesting possibilities. An immediate use case is the ability to use semconv as a mechanism to decouple the development of an application from the development of the observability infrastructure associated with that application (e.g., creating dashboards even before the application is developed). Telemetry-schema driven simulations is another long-term option :-)

I have a few requests for minor changes, and I would also like to get @jsuereth 's feedback on this PR.

Thanks again, this is really great!

Comment on lines +42 to +44
/// Write the telemetry to standard output
#[arg(long)]
stdout: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to the environment variable, I would find it more “discoverable” to have a parameter (or two) allowing the specification of the gRPC endpoint to target.


// For the given attribute, return a name/value pair.
// Values are generated based on the attribute type and examples where possible.
fn get_attribute_name_value(attribute: &Attribute) -> KeyValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

Supporting additional signals will significantly increase the number of methods used for generation and, consequently, the size of this file. Since we don’t know who will implement support for the other signals, I think it would be a good idea to create a new crate (e.g., weaver_emit) in /crates so that this current file contains only the essentials for defining the command interface, loading the registry, and calling the signal generation method.

fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
let exporter = opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.with_endpoint("http://localhost:4317")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use the default of the corresponding command parameter

Comment on lines +212 to +225
let rt = tokio::runtime::Runtime::new().expect("failed to create tokio runtime");
rt.block_on(async {
let tracer_provider = if args.stdout {
logger.mute();
init_stdout_tracer_provider()
} else {
init_tracer_provider().expect("OTLP Tracer Provider must be created")
};
let _ = global::set_tracer_provider(tracer_provider.clone());

emit_trace_for_registry(&registry, &args.registry.registry.to_string());

global::shutdown_tracer_provider();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the conversation with @jsuereth this morning, I think the creation of the Tokio runtime should be encapsulated in the weaver_emit crate mentioned earlier to avoid any async aspects at this level (even though it is honestly quite limited).

@jerbly
Copy link
Contributor Author

jerbly commented Jan 22, 2025

Totally agree with your comments @lquerel, and will go ahead with those changes. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants