Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: add custom instance name tags to instrumented services #329

Open
berler opened this issue Aug 5, 2019 · 1 comment
Open

FR: add custom instance name tags to instrumented services #329

berler opened this issue Aug 5, 2019 · 1 comment

Comments

@berler
Copy link

berler commented Aug 5, 2019

What happened?

We frequently create multiple instances of the same service in a single server (each instance may serve a different purpose or have an entirely different implementation). Frequently picking the instance to use is part of the server's API, although sometimes the instance is chosen with custom logic on the server for each request. We want to be able to instrument each these instances and distinguish which instance was used when creating metrics/log/trace events etc. Currently in order to distinguish between instances of the same service we need to give them distinct names (and can't use com.palantir.tritium.Tritium#instrument because the metric naming there is entirely determined by the service interface). This is our current workaround for instrumenting these:

    public static <T, U extends T> T instrument(
            Class<T> serviceInterface,
            U delegate,
            TaggedMetricRegistry metricRegistry,
            String instanceName) {
        String serviceName = MetricRegistry.name(serviceInterface, instanceName);
        return Instrumentation.builder(serviceInterface, delegate)
                .withTaggedMetrics(metricRegistry, serviceName)
                // ... similarly add logging and tracing, also with the custom name
                .build();
    }

This gets called once for each instance of the service (with a different instanceName for each instance).

What did you want to happen?

Having multiple instances of the same service interface in a single server should ideally be handled in a first-class way. The service instance name can be added as a tag (which would allow the metric names to be consistently determined by the interface class).

One possible implementation of this would be to add a custom map of tags to TaggedMetricsServiceInvocationEventHandler and also add helper methods in com.palantir.tritium.Tritium where the instance name is an argument (in addition to all the existing args). The implementation doesn't matter as much as having a simple method to call where the args should be:

  • Class<T> serviceInterfance
  • U delegate
  • TaggedMetricRegistry metricRegistry
  • String instanceName

And the result is an instrumented service where the instanceName gets added to metrics (and logging/tracing etc) as a tag.

@schlosna
Copy link
Contributor

schlosna commented Aug 9, 2019

@carterkozak for thoughts as he was looking for similar recently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants