github.com/twitchtv/twirp

github.com/twitchtv/twirp

A simple RPC framework with protobuf service definitions.

Details & Caveats

  • This instrumentation currently uses the wrappers from the dd-trace-go contrib/net/http package, not the ones from contrib/twitchtv/twirp.
  • The server-side instrumentation additionally adds rpc / twirp specific spans using *twirp.ServerHooks.
  • Currently, the *twirp.ClientHooks implementation is not available in dd-trace-go, so the only generated spans are the ones from net/http.

Add twirp server hooks

Join Point
Struct literal twirp.ServerOptions
  • Pointer or Value
Advice
Replace the expression using the template:
// Using the following synthetic imports:
import (
	twirp "github.com/twitchtv/twirp"
	twirptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/twitchtv/twirp"
)
{{- .AST.Type -}}{
	{{- $hasField := false -}}
	{{ range .AST.Elts }}
	{{- if eq .Key.Name "Hooks" }}
	{{- $hasField = true -}}
	Hooks: twirp.ChainHooks(twirptrace.NewServerHooks(), {{ .Value }}),
	{{- else -}}
	{{ . }},
	{{ end -}}
	{{ end }}
	{{- if not $hasField -}}
	Hooks: twirptrace.NewServerHooks(),
	{{- end }}
}