Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Recap: Automatically Instrument Your Go Source ...

Recap: Automatically Instrument Your Go Source Code with Orchestrion

Shunta Komatsu

November 01, 2023
Tweet

More Decks by Shunta Komatsu

Other Decks in Technology

Transcript

  1. 1 Recap: Automatically Instrument Your Go Source Code with Orchestrion

    mercari.go #24 - GopherCon 2023 Recap Shunta Komatsu
  2. 2 About me • Shunta Komatsu • Backend Engineer at

    Merpay ◦ Developing the payment platform • Joined Merpay in April 2022
  3. 4 What kind of presentation? Introduction of a tool “Orchestrion”

    developed by Datadog • The tool generates Datadog APM traces in Go code • More of code instrumentation rather than code generation • https://github.com/DataDog/orchestrion
  4. 5 What is traces? • Traces show the flow of

    data within and between the components • A trace has one or more span(s) • Span is a section of interesting activity in your program ◦ receiving an HTTP request, calling in database, etc. https://www.datadoghq.com/product/apm/
  5. 7 • You need to set up all traces •

    You have to make sure you properly close your traces and spans When you add handlers
  6. 8 Motivations behind orchestrion • Go doesn’t do magic ◦

    Java provides “annotation” ◦ Python provides “decorator” • Instead, Go is simple and easy to parse the AST • Orchestrion generates code to add traces and spans https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/python/ https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/java/
  7. 10 What does generated code do? • Launch the tracer

    • Stop the tracer as defer • Embed metadata package: github.com/orchestrion/instrument
  8. 12 (Appendix) What Is dd-trace-go.v1/contrib package? • https://github.com/DataDog/dd-trace-go/tree/main/contrib • A

    package to make tracer easier to use in various web frameworks, SQL frameworks, etc. ◦ gin-gonic/gin ◦ go-chi/chi ◦ labstack/echo ◦ net/http ◦ …
  9. 13 Flexible usage • Orchestrion provides the –rm option ◦

    You can revert to what it was before Orchestrion adde code • Any span tags can be set with dd:span magic comment
  10. 14 How it works • Orchestrion scans each source code

    with the dave/dst package to get AST ◦ The standard go/ast package doesn’t attach comments to nodes
  11. 15 Impressions of this session • Orchestrion is easy to

    use and reversible to change, and you’ll be able to try it out in no time • However, it still lacks functionality and would be especially difficult to apply to large repositories and microservices ◦ Ignore is not supported ◦ OpenTelemetry is not supported • The gopkg.in/DataDog/dd-trace-go.v1 package already has orchestrionConfig in the tracer.config struct, so the feature will be enhanced in the future
  12. 16 Summary • Orchestrion installs the trace with just one

    line of command ◦ You don’t have to worry about forgetting to add spans • However, it may be better not to use it until more flexibility is brought to the functionality