$30 off During Our Annual Pro Sale. View Details »

Recap: Automatically Instrument Your Go Source Code with Orchestrion

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

    View Slide

  2. 2
    About me
    ● Shunta Komatsu
    ● Backend Engineer at Merpay
    ○ Developing the payment platform
    ● Joined Merpay in April 2022

    View Slide

  3. 3
    What kind of presentation?
    https://www.gophercon.com/agenda/session/1160499

    View Slide

  4. 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

    View Slide

  5. 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/

    View Slide

  6. 6
    ● Just adding some code
    How to gather data?

    View Slide

  7. 7
    ● You need to set up all traces
    ● You have to make sure you properly close
    your traces and spans
    When you add handlers

    View Slide

  8. 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/

    View Slide

  9. 9
    Demo of Orchestrion
    1. Prepare the initial code
    2. Run orchestrion -w .

    View Slide

  10. 10
    What does generated code do?
    ● Launch the tracer
    ● Stop the tracer as defer
    ● Embed metadata
    package: github.com/orchestrion/instrument

    View Slide

  11. 11
    What does generated code do?
    package: github.com/orchestrion/instrument
    package: gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http
    package: gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer

    View Slide

  12. 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
    ○ …

    View Slide

  13. 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

    View Slide

  14. 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

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. 17
    The Go gopher was designed by Renee French
    Thanks for your attention!

    View Slide