Git Product home page Git Product logo

Comments (2)

liamwh avatar liamwh commented on July 30, 2024

Found the solution. I still think adding an example is a good idea, and I'm also wondering if a builder param behind a feature flag makes sense here to automate all this boilerplate?

 let builder = cloudevents::EventBuilderV10::new()
      .id(Ulid::new())
      .source(SOURCE_NAME)
      .ty(EXAMPLE_EVENT_TYPE)
      .time(chrono::Utc::now())
      .subject(example_object.id)
      .data(
          mime::APPLICATION_OCTET_STREAM.to_string(),
          bincode::serialize(&example_object)?,
      )

  let span = tracing::Span::current();
  let otel_context = span.context();
  let span = otel_context.span();
  let span_context = span.span_context();
  if span_context.is_sampled() {
      let trace_id = span_context.trace_id().to_bytes();
      let span_id = span_context.span_id().to_bytes();
      let trace_flags = span_context.trace_flags().to_u8();
      let trace_id_hex = hex::encode(trace_id);
      let span_id_hex = hex::encode(span_id);
      let traceparent = format!("00-{}-{}-{:02x}", trace_id_hex, span_id_hex, trace_flags);
      builder = builder.extension("traceparent", traceparent);
  }
  let example_event = builder.build()?;

from sdk-rust.

Lazzaretti avatar Lazzaretti commented on July 30, 2024

That would be nice (example & feature flag)! I will happily review a PR if you have time to contribute something.

from sdk-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.