Skip to content

Commit 798dc52

Browse files
committed
feat: instrumented otel with SigNoz backend
0 parents  commit 798dc52

9 files changed

Lines changed: 1765 additions & 0 deletions

File tree

.gitignore

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Electron OpenTelemetry Example Application
2+
3+
This Electron application demonstrates basic OpenTelemetry instrumentation for monitoring and tracing, designed to work with SigNoz Cloud for visualization. It showcases how to trace application startup, simulate long-running tasks, read file contents, and handle user interactions with OpenTelemetry in an Electron app.
4+
5+
## Application Screenshot
6+
7+
![Application Screenshot](PATH_TO_YOUR_APPLICATION_SCREENSHOT)
8+
9+
This screenshot shows the Electron application's interface.
10+
11+
## Backend Traces Screenshot in SigNoz Cloud
12+
13+
![Backend Traces Screenshot in SigNoz Cloud](PATH_TO_YOUR_BACKEND_TRACES_SCREENSHOT)
14+
15+
The above screenshot displays the traces as they appear in SigNoz Cloud. This visualizes the telemetry data collected from the application, including trace details for application startup, simulated tasks, and user actions.
16+
17+
## Getting Started
18+
19+
To run this Electron OpenTelemetry example application on your system and visualize traces in SigNoz Cloud, follow the steps outlined below. These instructions assume you have Node.js and npm installed. If not, please install them from [Node.js official site](https://nodejs.org/).
20+
21+
### 1. Clone the Repository
22+
23+
First, clone the repository to your local machine:
24+
25+
```bash
26+
git clone https://github.com/YOUR_GITHUB/YOUR_REPOSITORY.git
27+
cd YOUR_REPOSITORY
28+
```
29+
30+
### 2. Install Dependencies
31+
32+
Inside the project directory, install the necessary dependencies:
33+
34+
```bash
35+
npm install
36+
```
37+
38+
### 3. Run the Application
39+
40+
Once the dependencies are installed, you can start the Electron application with:
41+
42+
```bash
43+
npm start
44+
```
45+
46+
This command launches the Electron app window and begins tracing application activities.
47+
48+
### 4. View Traces in SigNoz Cloud
49+
To view the traces generated by your application:
50+
51+
- Ensure your SigNoz Cloud instance is up and running and correctly configured in `tracing.js`.
52+
- Perform actions within the application (e.g., clicking the demonstrated button, and waiting for the application to read the file content).
53+
- Access your SigNoz Cloud dashboard **Service Tab** to view your application.
54+
55+
You should see a service called `electronjs-otel-sample-app` in your Service Tab. You can change the name of your service in your `tracing.js`.
56+
57+
--------------------------------
58+
59+
Read the comments in `tracing.js` and `index.js` files to get a better understanding of how the instrument works. OpenTelemetry doesn't provide auto-instrumentation for ElectronJS so you have to manually instrument all the functions that you want to collect the traces for.

example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, this is a test file for the Electron instrumentation example with SigNoz.

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Electron Tracing Example</title>
5+
</head>
6+
<body>
7+
<h1>Electron OpenTelemetry Tracing</h1>
8+
<button id="myButton">Click Me</button>
9+
<script src="renderer.js"></script>
10+
</body>
11+
</html>

index.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Import necessary modules from Electron, the file system, and the path utility.
2+
const { app, BrowserWindow, ipcMain } = require('electron');
3+
const fs = require('fs').promises;
4+
const path = require('path');
5+
// Import the OpenTelemetry tracer you've configured in tracing.js for creating spans.
6+
const tracer = require('./tracing');
7+
8+
// Defines an asynchronous function to simulate a time-consuming task.
9+
async function simulateLongRunningTask() {
10+
// Start a new span for tracing this task.
11+
const span = tracer.startSpan('simulateLongRunningTask');
12+
try {
13+
// Simulate a delay of 2000 milliseconds (2 seconds).
14+
await new Promise(resolve => setTimeout(resolve, 2000));
15+
// Record an event indicating the task is completed.
16+
span.addEvent('Task completed');
17+
} catch (error) {
18+
// Record any exceptions that occur during the task.
19+
span.recordException(error);
20+
} finally {
21+
// End the span once the task is complete or if an error occurred.
22+
span.end();
23+
}
24+
}
25+
26+
// Defines an asynchronous function to read the contents of a file named 'example.txt'.
27+
async function readFileContents() {
28+
// Start a new span for tracing the file reading operation.
29+
const span = tracer.startSpan('readFileContents');
30+
try {
31+
// Read the contents of the file asynchronously.
32+
const data = await fs.readFile(path.join(__dirname, 'example.txt'), 'utf8');
33+
// Log the data to the console.
34+
console.log(data);
35+
// Record an event indicating the file was read successfully.
36+
span.addEvent('File read successfully');
37+
} catch (error) {
38+
// Record any exceptions that occur while reading the file.
39+
span.recordException(error);
40+
console.error('Error reading file:', error);
41+
} finally {
42+
// End the span once the operation is complete or if an error occurred.
43+
span.end();
44+
}
45+
}
46+
47+
// Defines an asynchronous function to create a new browser window and load the HTML file.
48+
async function createWindow() {
49+
// Start a new span for tracing the application startup process.
50+
const span = tracer.startSpan('ApplicationStart');
51+
// Create a new browser window with specific dimensions and web preferences.
52+
const win = new BrowserWindow({
53+
width: 800,
54+
height: 600,
55+
webPreferences: {
56+
nodeIntegration: true,
57+
contextIsolation: false, // Important for security, see Electron documentation.
58+
},
59+
});
60+
// Load an HTML file into the window.
61+
win.loadFile('index.html');
62+
63+
// Perform additional tasks as part of the startup process.
64+
await simulateLongRunningTask();
65+
await readFileContents();
66+
67+
// End the span for the application startup process.
68+
span.end();
69+
}
70+
71+
// Listen for the 'whenReady' event to create the browser window.
72+
app.whenReady().then(createWindow);
73+
74+
// Listen for 'button-click' messages sent from renderer processes.
75+
ipcMain.on('button-click', async () => {
76+
// Start a new span for tracing the button click action.
77+
const span = tracer.startSpan('buttonClick');
78+
try {
79+
// Simulate processing related to the button click.
80+
await new Promise(resolve => setTimeout(resolve, 1000));
81+
// Record an event indicating the action related to the button click is completed.
82+
span.addEvent('Button action completed');
83+
} catch (error) {
84+
// Record any exceptions that occur during the processing.
85+
span.recordException(error);
86+
} finally {
87+
// End the span once the action is complete or if an error occurred.
88+
span.end();
89+
}
90+
});
91+
92+
// Listen for the 'window-all-closed' event to quit the application on non-macOS platforms.
93+
app.on('window-all-closed', () => {
94+
if (process.platform !== 'darwin') {
95+
app.quit();
96+
}
97+
});

0 commit comments

Comments
 (0)