Skip to main content

Overview

Attributes and tags are two ways to add metadata to traces:
  • Attributes: Key-value pairs for detailed, queryable data
  • Tags: Simple labels for categorization and filtering

Attributes

Adding Single Attributes

trace.addAttribute('userId', 'user-123')
     .addAttribute('amount', 1.5)
     .addAttribute('currency', 'ETH');

Adding Multiple Attributes

trace.addAttributes({
  from: '0xabc...',
  to: '0xdef...',
  value: '1.5',
  gasLimit: 21000
});

Complex Values

Objects are automatically stringified to JSON:
trace.addAttribute('config', {
  slippage: 0.5,
  deadline: 300,
  route: ['ETH', 'USDC', 'DAI']
});
// Stored as: '{"slippage":0.5,"deadline":300,"route":["ETH","USDC","DAI"]}'

Common Attribute Patterns

// User context
trace.addAttributes({
  userId: user.id,
  walletAddress: user.wallet,
  sessionId: session.id
});

// Transaction details
trace.addAttributes({
  txHash: receipt.hash,
  blockNumber: receipt.blockNumber,
  gasUsed: receipt.gasUsed.toString()
});

// Operation parameters
trace.addAttributes({
  inputToken: 'ETH',
  outputToken: 'USDC',
  inputAmount: '1.5',
  slippage: '0.5%'
});

Tags

Adding Single Tags

trace.addTag('ethereum')
     .addTag('swap')
     .addTag('production');

Adding Multiple Tags

trace.addTags(['dex', 'uniswap', 'v3']);

Tag Use Cases

Tags are ideal for:
  • Chain identification: ethereum, polygon, arbitrum
  • Operation type: swap, transfer, mint, stake
  • Environment: production, staging, development
  • Feature flags: beta, experimental
  • Priority: critical, high, normal
const trace = client.trace({ name: 'NFTMint' })
  .addTags(['nft', 'mint', 'ethereum', 'production']);

Attributes vs Tags

AspectAttributesTags
StructureKey-value pairsSimple strings
Use caseDetailed dataCategorization
QueryabilityFilter by key and valueFilter by presence
ExampleuserId: "123""ethereum"

When to Use Attributes

  • Specific values you’ll query: user IDs, amounts, addresses
  • Data that varies per trace: transaction hashes, block numbers
  • Structured information: configuration objects

When to Use Tags

  • Categories that group traces: chain names, operation types
  • Boolean-like flags: is this production? is this a swap?
  • Simple labels for filtering dashboards

Method Signatures

Attributes

addAttribute(key: string, value: string | number | object): Trace
addAttributes(attrs: Record<string, string | number | object>): Trace

Tags

addTag(tag: string): Trace
addTags(tags: string[]): Trace

Best Practices

Be Consistent with Keys

Use a consistent naming convention:
// Good - consistent camelCase
trace.addAttributes({
  userId: '123',
  walletAddress: '0x...',
  transactionHash: '0x...'
});

// Avoid - mixed conventions
trace.addAttributes({
  user_id: '123',
  WalletAddress: '0x...',
  'transaction-hash': '0x...'
});

Don’t Store Sensitive Data

Avoid including private keys, passwords, or PII:
// Good
trace.addAttribute('walletAddress', publicAddress);

// Never do this
trace.addAttribute('privateKey', wallet.privateKey);

Use Meaningful Tag Names

Tags should be immediately understandable:
// Good
trace.addTags(['ethereum', 'swap', 'uniswap']);

// Avoid
trace.addTags(['eth', 'sw', 'uni']);

Next Steps