Skip to content

Ability to add tracing options to auto-wired libraries #61

@mlund01

Description

@mlund01

In search of being able to set the service name on the tracer of my database/sql client, it came to my attention that there is no current way to set the options through orchestrion. After digging a little deeper into the internals, I noticed the underlying tracer function (coming from gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql) is variadic, with the ability to pass 0 or many options, so it is pretty straightforward to add, if only there is a way to tell orchestrion what to add as options.

Proposal

I would like to propose adding another "magic comment" in orchestrion called //dd:options that can be used directly above an instantiation of one of the supported auto-wire libs. It would be used like so,

package main

import "database/sql"

func main() {
	//dd:options service:test-name tag:my_key:my_val
	db, err := sql.Open("driver", "connectionString")
}

Doing so would generate the following code,

package main

import "github.com/datadog/orchestrion/instrument"

func register() {
	//dd:options service:test-name tag:my_key:my_val
	//dd:startwrap
	db, err := instrument.Open("driver", "connString", instrument.SqlWithServiceName("test-name"), instrument.SqlWithCustomTag("my_key", "my_value"))
	//dd:endwrap
}

This proposal requires the instrument.Open function that currently accepts 2 params and is non-variadic to accept 2+ params with the last param being variadic and accept 0 or many options. This function is for database/sql, but the same general need applies to the other supported libs.

Some other questions that should be discussed and answered,

  • one vs many entries on the comment line: Some options support passing many (such as custom tags... I think anyways), while others should only be passed once (like service name). Should orchestrion be smart enough to know which ones support one vs. many and throw an error if invalid?
  • invalid options: if an invalid/unsupported option is passed in the magic comment, should orchestrion throw an error, inform the user, or do nothing?

I got a bit ahead of myself and put together a PR, but can change as necessary if the broader proposal is accepted.

The PR: #60

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions