Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: synchronous init #539

Merged
merged 11 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/push-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
needs: [build-package]
strategy:
matrix:
node_cimg_tag: [ 10, 12 ]
node_cimg_tag: [ 12 ]
steps:
- name: Set up Node
uses: actions/setup-node@v3
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,33 @@ If the [Task Metadata endpoint v4](https://docs.aws.amazon.com/AmazonECS/latest/

### Waiting for the initialization of the Lumigo OpenTelemetry Distro

The initialization of the Lumigo OpenTelemetry Distro is performed asynchronously to avoid potentially blocking behavior.
The initialization of the Lumigo OpenTelemetry Distro is performed asynchronously by default, to avoid potentially blocking behavior. See the [synchronous initialization] section(#synchronous-initialization-of-the-Lumigo-OpenTelemetry-Distro) for an alternate method of initializing.

Due to the asynchronous nature of this initialization logic, some CLI or batch-like applications that perform their logic on startup without needing to wait on external request responses may find that they are missing some of the trace data, for example the first span that represents the startup of the application.

For scenarios in which each and every span is required, the Lumigo OpenTelemetry Distro provides a `Promise` called `init` that you can wait on as follows:

### Synchronous initialization of the Lumigo OpenTelemetry Distro

For cases where the startup time is not a great concern, and you want to ensure that all spans and logs are captured, an alternative initialization method is available via the `@lumigo/oprntelemetry/sync` entrypoint. This entrypoint will block the main thread until the Lumigo OpenTelemetry Distro is fully initialized, without the need to wait on the `init` promise, and will provide an already-initialized Lumigo SDK objects:


```typescript
import { tracerProvider, loggerProvider } from '@lumigo/opentelemetry/sync';
```

```js
const { tracerProvider, loggerProvider } = require('@lumigo/opentelemetry/sync');
```

This will also possible with preloading, using the `-r` None option:

```bash
node -r '@lumigo/opentelemetry/sync' your-app-main-file.js
```

these methods will ensure that your app will wait for the Lumigo OpenTelemetry Distro to be fully initialized before attempting to capture and export any telemetry data.

#### Node.js prior to v18

```typescript
Expand Down
Loading
Loading