Controller#action_name, BackgroundWorker#perform, etc.).
When the automatically determined action name is not good enough, you can customize the action name.
This guide explains how to customize action names in different language integrations.
Why Customize Action Names?
- Improved clarity: Provide more descriptive names for complex operations.
- Customized grouping: Control how application data is organized in the AppSignal.
When Automatic Action Names Fall Short
Here are some examples where automatically generated action names may not be good enough:- Catch-all routes: In applications that use catch-all routes or dynamic routing (like
/api/:entity/:action), the default action name might be something generic likeApiController#dispatch. - Multi-purpose tasks: Background workers and scripts that handle different types of work based on parameters that would all be grouped under the same action name (e.g.,
GenericWorker#perform). - GraphQL resolvers: These might all be grouped under a single action name (e.g.
POST /graphql) despite handling many different types of operations.
Customizing Actions Per Language
Ruby
In Ruby applications, you can use theAppsignal.set_action helper to customize the action name:
Appsignal.set_action helper.
It’s also possible to configure the action name when creating a transaction using the Appsignal.monitor helper. It accepts the action name as a keyword argument.
Elixir
In Elixir applications, you can use theAppsignal.Span.set_name/2 function to customize the action name on the root span:
Appsignal.Span.set_name/2 function.
Node.js
In Node.js applications, you can use thesetRootName helper from the AppSignal package to customize action names:
setRootName helper.
Python
In Python applications, you can use theset_root_name helper from the AppSignal package to customize action names:
set_root_name helper.
Front-end JavaScript
In Front-end JavaScript applications, you can use thesetAction helper from the AppSignal package to customize action names:
Go
In Go applications, AppSignal works with OpenTelemetry, which uses spans to track metadata, such as the action name. On any span in the trace, set anappsignal.action_name attribute with a String value to customize the action name:
appsignal.action_name attribute on the active span.
Java
In Java applications, AppSignal works with OpenTelemetry, which uses spans to track metadata, such as the action name. On any span in the trace, set anappsignal.action_name attribute with a String value to customize the action name:
appsignal.action_name attribute on the active span.
PHP
In PHP applications, you can use theAppsignal::setAction() helper method from the AppSignal package to customize action names:
appsignal.action_name attribute on the active span.
Best Practices
When customizing action names, follow these guidelines:- Be consistent: Use a consistent naming pattern across your application.
- Be specific: Include relevant information that helps identify the operation.
- Avoid high cardinality: Don’t include unique IDs or values that would create unique action names per execution.
- Use static strings: Never interpolate variables or dynamic data into action names.
- Follow the codebase naming: Use naming patterns like
Controller#actionthat match your application structure so the location in the code can be found. - Use tags or metadata instead: For tracking variable information like payment providers or user types, use tags and metadata rather than incorporating them into action names.
How to Handle Different Operations with the Same Action Name
Instead of creating dynamic action names, use a combination of:- Static action names: Use descriptive but static action names.
- Tags: Add tags with the variable information (e.g.,
provider: stripe,operation_type: refund). - Custom attributes: Add additional metadata to the trace/transaction.
- Group related operations under a single action name.
- Filter and search based on tags.
- Maintain a clean incident overview.