Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c022264
Implement perf events
TatianaFomina Mar 15, 2025
0bc0093
feat(performance): enhance performance monitoring with batch sending …
TatianaFomina Mar 15, 2025
767592b
Lint
TatianaFomina Mar 15, 2025
ab1ab01
Upd
TatianaFomina Mar 15, 2025
751a048
Upd
TatianaFomina Mar 15, 2025
5daeb4e
Upd api
TatianaFomina Mar 15, 2025
b5d71c4
Remove traceId
TatianaFomina Mar 15, 2025
d708ebb
feat(performance): add performance monitoring
TatianaFomina Mar 15, 2025
1c7a123
feat(performance): enhance performance monitoring configuration and s…
TatianaFomina Mar 15, 2025
2cabdaa
feat(performance): add performance monitoring settings demo with tran…
TatianaFomina Mar 15, 2025
a0d56bb
refactor(performance): simplify transaction queuing and remove unused…
TatianaFomina Mar 15, 2025
933f7f9
refactor(performance): update PerformancePayload interface to include…
TatianaFomina Mar 15, 2025
6c544bd
Lint
TatianaFomina Mar 15, 2025
8309ae3
Fix
TatianaFomina Mar 15, 2025
d611f1d
Review
TatianaFomina Mar 15, 2025
2459f5d
feat(performance): introduce batch sending configuration and enhance …
TatianaFomina Mar 15, 2025
c1639ca
feat(performance): add batch interval configuration and update UI for…
TatianaFomina Mar 15, 2025
c8b37bc
style: clean up code formatting and remove unnecessary whitespace in …
TatianaFomina Mar 15, 2025
1e57084
chore(performance): remove debugger statement from startTransaction m…
TatianaFomina Mar 15, 2025
8e8d0f7
Split
TatianaFomina Mar 16, 2025
efa12f9
Review
TatianaFomina Mar 16, 2025
677fdaf
feat(performance): update HawkCatcher initialization and enhance perf…
TatianaFomina Mar 16, 2025
1f1e758
fix(performance): correct transaction length reference and update bat…
TatianaFomina Mar 16, 2025
93fd56c
Add doc
TatianaFomina Mar 16, 2025
846e864
Update performance-monitoring.md
neSpecc Mar 16, 2025
e510e2a
Update performance-monitoring.md
neSpecc Mar 16, 2025
cefde4d
Update performance-monitoring.md
neSpecc Mar 16, 2025
e6885ca
Update performance-monitoring.md
neSpecc Mar 16, 2025
366ca89
Update respectively to docs
TatianaFomina Mar 16, 2025
936da97
Upd
TatianaFomina Mar 16, 2025
6ffcf16
Update readme
TatianaFomina Mar 16, 2025
e007868
Refactor HawkCatcher initialization in monitoring.html to use a const…
TatianaFomina Mar 16, 2025
bbc9cea
Merge branch 'master' into feat/perf
TatianaFomina Mar 16, 2025
f11bdd1
Enhance performance monitoring by adding critical duration threshold …
TatianaFomina Mar 16, 2025
c4f0094
Refactor performance monitoring code by adding missing commas for con…
TatianaFomina Mar 16, 2025
e5a32ca
Add retries
TatianaFomina Mar 16, 2025
17c44f5
Enhance performance monitoring by adding detailed documentation for S…
TatianaFomina Mar 16, 2025
61649a9
Refactor consoleCatcher and performance monitoring code for improved …
TatianaFomina Mar 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 175 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Then import `@hawk.so/javascript` module to your code.

```js
import HawkCatcher from '@hawk.so/javascript';
````
```

### Load from CDN

Expand Down Expand Up @@ -74,6 +74,7 @@ Initialization settings:
| `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling |
| `disableVueErrorHandler` | boolean | optional | Do not initialize Vue errors handling |
| `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk |
| `performance` | boolean\|object | optional | Performance monitoring settings. When object, accepts: <br> - `sampleRate`: Sample rate (0.0 to 1.0, default: 1.0) <br> - `batchInterval`: Batch send interval in ms (default: 3000) |

Other available [initial settings](types/hawk-initial-settings.d.ts) are described at the type definition.

Expand Down Expand Up @@ -151,7 +152,6 @@ const hawk = new HawkCatcher({

or pass it any moment after Hawk Catcher was instantiated:


```js
import Vue from 'vue';

Expand All @@ -161,3 +161,176 @@ const hawk = new HawkCatcher({

hawk.connectVue(Vue)
```

## Performance Monitoring

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • explain what is Transaction and Span.
  • move API Reference on the first place
  • optimization explanation is a technical detail, so it should be placed after usage description

The SDK can monitor performance of your application by tracking transactions and spans.

### Transaction Batching

By default, transactions are collected and sent in batches every 3 seconds to reduce network overhead.
You can configure the batch interval using the `batchInterval` option:

```js
const hawk = new HawkCatcher({
token: 'INTEGRATION_TOKEN',
performance: {
batchInterval: 5000 // Send batches every 5 seconds
}
});
```

Transactions are automatically batched and sent:
- Every `batchInterval` milliseconds
- When the page is unloaded (in browser)
- When the process exits (in Node.js)

### Sampling

You can configure what percentage of transactions should be sent to Hawk using the `sampleRate` option:

```typescript
const hawk = new HawkCatcher({
token: 'INTEGRATION_TOKEN',
performance: {
sampleRate: 0.2
}
});
```

Features:
- Track transactions and spans with timing data
- Automatic span completion when transaction ends
- Support for both browser and Node.js environments
- Debug mode for development
- Throttled data sending to prevent server overload
- Graceful cleanup on page unload/process exit

> Note: If performance monitoring is not enabled, `startTransaction()` will return undefined and log an error to the console.

### API Reference

#### startTransaction(name: string, tags?: Record<string, string>): Transaction

Starts a new transaction. A transaction represents a high-level operation like a page load or an API call.

- `name`: Name of the transaction
- `tags`: Optional key-value pairs for additional transaction data

#### startSpan(transactionId: string, name: string, metadata?: Record<string, any>): Span

Creates a new span within a transaction. Spans represent smaller units of work within a transaction.

- `transactionId`: ID of the parent transaction
- `name`: Name of the span
- `metadata`: Optional metadata for the span

#### finishSpan(spanId: string): void

Finishes a span and calculates its duration.

- `spanId`: ID of the span to finish

#### finishTransaction(transactionId: string): void

Finishes a transaction, calculates its duration, and sends the performance data to Hawk.

- `transactionId`: ID of the transaction to finish

### Data Model

#### Transaction
```typescript
interface Transaction {
id: string;
name: string;
startTime: number;
endTime?: number;
duration?: number;
tags: Record<string, string>;
spans: Span[];
startSpan(name: string, metadata?: Record<string, any>): Span;
finish(): void;
}
```

#### Span
```typescript
interface Span {
id: string;
transactionId: string;
name: string;
startTime: number;
endTime?: number;
duration?: number;
metadata?: Record<string, any>;
finish(): void;
}
```

### Examples

#### Measuring Route Changes in Vue.js
```javascript
import { Catcher } from '@hawk.so/javascript';
import Vue from 'vue';
import Router from 'vue-router';

const hawk = new Catcher('your-integration-token');

router.beforeEach((to, from, next) => {
const transaction = hawk.startTransaction('route-change', {
from: from.path,
to: to.path
});

next();

// After route change is complete
Vue.nextTick(() => {
transaction.finish();
});
});
```

#### Measuring API Calls
```javascript
async function fetchUsers() {
const transaction = hawk.startTransaction('fetch-users');

const apiSpan = transaction.startSpan('GET /api/user', {
url: '/api/users',
method: 'GET'
});

try {
const response = await fetch('/api/users');
const data = await response.json();

apiSpan.finish();

const processSpan = transaction.startSpan('process-data');
// Process data...
processSpan.finish();

return data;
} finally {
transaction.finish();
}
}
```

### Configuration

- `token`: Your project's Integration Token
- `release`: Unique identifier of the release. Used for source map consuming
- `user`: Current authenticated user
- `context`: Any data you want to pass with every message. Has limitation of length.
- `vue`: Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application)
- `disableGlobalErrorsHandling`: Do not initialize global errors handling
- `disableVueErrorHandler`: Do not initialize Vue errors handling
- `beforeSend`: This Method allows you to filter any data you don't want sending to Hawk
- `performance`: Enable/disable performance monitoring
- `true`: Enable with 100% sampling
- `{sampleRate: number}`: Enable with custom sampling rate (0.0 to 1.0)
- `false` or `undefined`: Disable performance monitoring
Loading