Inspector
BlogTry for free
  • Concepts
    • Introduction
    • Metrics
    • Notification Channels
      • Email
      • Slack
      • Telegram
      • Microsoft Teams
      • Google Chat
      • Webhook
      • Discord
      • Pushover
      • PagerDuty
      • Twilio - SMS
    • Filtering Syntax
    • Alerts
    • Grouping Patterns
    • Custom Segments
    • Billing
    • AI Bug Fixer
  • Security and access
    • Access control
    • Two-factor authentication
    • Connected Devices
  • SDK
    • PHP
      • Installation & Set Up
      • Custom Segments
      • Exceptions Monitoring
      • Configuration
    • Laravel / Lumen
      • Upgrade Guide
      • Installation & Set-up
      • Http Requests Monitoring
      • Configuration
      • Exception Monitoring
      • Laravel Vapor
      • Laravel Octane
      • Laravel Nova Tool
      • Group by service name
    • Symfony
      • Installation
      • Configuration
      • Exception Monitoring
    • CodeIgniter
      • Installation
      • Configuration
      • Exception Monitoring
    • Drupal
    • Spring Boot
    • Slim
    • NodeJS
      • Configurations
      • Custom Segments
      • Exception monitoring
      • Autowiring
    • ExpressJs
    • Fastify
    • Python
    • Django
      • Installation & Set Up
      • Custom Segments
      • Error Monitoring
  • REST API
    • Authentication
    • Apps
    • Platforms
    • Transactions
    • Segments
    • Analytics
Powered by GitBook
On this page
  • Add a Segment (short form)
  • Get return
  • Working with Promise
  • Add contextual informations
  1. SDK
  2. NodeJS

Custom Segments

Monitor custom code blocks in your nodejs application.

PreviousConfigurationsNextException monitoring

Last updated 1 year ago

Add a Segment (short form)

Just a few lines of code are needed:

inspector.addSegment(() => {
    
    // Your statements here...
    
}, 'type', 'label');

This will produce a new segment in the timeline:

As showed in the example above a new segment is built with three input parameters:

Parameter

Required

Description

callback

YES

The code block you want keep under real-time monitoring

type

YES

This is the master category of your segments

label

NO

Human readable label or specific task name that will be showed inside the timeline in your Inspector dashboard. If it isn't provided type is used as label.

Think about how database queries is reported. That's one master category like mysql but each query has its own custom label that simply is an extract of the sql code executed for a better timeline consultation.

  • mysql: master type

  • select * from table...: label

In this way you can mark toghether the statements related to a specific task using something like csv-export as type parameter and use the filename as label for each statement of this type.

Get return

What you return from your callback will be returned back by addSegment() method.

/**
 * "result " will contains the string "Hello".
 * 
 * Note the use of "await".
 */
let result = await inspector.addSegment(() => {
    
    // Your statements here...
    
    return 'Hello';
    
}, 'csv-export', csvFileName);

Working with Promise

// Use await
await inspector.addSegment(...);

// Use then/catch
inspector.addSegment(...)
    .then()
    .catch();

Add contextual informations

If you need to report some contextual information, the new segment will be injected as callback parameter:

/**
 * "result " will contains the string "Hello"
 */
let result = await inspector.addSegment(segment => {
    
    // Your statements here...
    
    // Attach interesting data
    segment.addContext('payload', {
        foo: 'bar'
    });
    
    // return a result if needed
    return 'Hello';
    
}, 'csv-export', csvFileName);

inspector.addSegment() return a . See the section below to learn more.

inspector.addSegment() return a . If you want wait the execution of the callback you need to use async/await construct or then/catch.

Promise
Promise
Working with Promise
A new segment in the timeline