Slide 1

Slide 1 text

1 Recap: Automatically Instrument Your Go Source Code with Orchestrion mercari.go #24 - GopherCon 2023 Recap Shunta Komatsu

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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/

Slide 6

Slide 6 text

6 ● Just adding some code How to gather data?

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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/

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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