Menu
Grafana Cloud

Override the service name attribute

Faro provides APIs to dynamically change the service name as the user navigates your application. The Faro receiver updates the service name attributes in the logs and traces immediately.

This feature becomes useful in cases such as when multiple teams own parts of the product. Instead of using multiple isolated Faro instances running in the same browsing context, you can just change the service name.

The following properties appear updated in the resulting telemetry:

  • service.name: resource attribute on traces and spans
  • resource_service_name: in logs

How it works

When triggering a service name change, Faro updates the session metadata with an overrides object which contains the new service name. The Faro receiver reads the instruction and updates the service name for all subsequent signals until another service name is set. The service name change persists across page loads.

Change a service name

You can change the service name by calling either the setView() or setSession() APIs. Both APIs have a second options parameter, which can instruct Faro to change the service name.

Use the setView() API

Change the view name and service name:

typescript
faro.api.setView({ name: 'my-new-view' }, { overrides: { serviceName: 'my-new-view-service' } });

Use the setSession() API

Change the session metadata and service name:

typescript
faro.api.setSession(mySessionMeta, { overrides: { serviceName: 'my-new-view-service' } });

If the sessions meta parameter is empty, Faro creates a new session and adds the overrides to that session.

ts
faro.api.setSession(undefined, { overrides: { serviceName: 'my-new-view-service' } });