Skip to content

Commit

Permalink
Sample send events
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT committed Nov 26, 2023
1 parent b39ecfc commit db73d24
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changeset/long-hounds-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@spotlightjs/overlay': patch
'@spotlightjs/sidecar': patch
---

Remove connect function from sidecar
File renamed without changes.
53 changes: 53 additions & 0 deletions packages/overlay/_fixtures/send_to_sidecar.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node
const fs = require('fs');
const http = require('http');
const path = require('path');

// Directory where the script is running
const directoryPath = path.join(__dirname);

// Function to read files and send data
function sendData(filePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file ${filePath}: ${err}`);
return;
}

const options = {
hostname: 'localhost',
port: 8969,
path: '/stream',
method: 'POST',
headers: {
'Content-Type': 'application/x-sentry-envelope',
},
};

const req = http.request(options, res => {
console.log(`Status: ${res.statusCode}`);
});

req.on('error', error => {
console.error(`Problem with request: ${error.message}`);
});

// Send the data
req.write(data);
req.end();
});
}

// Read all .txt files from the directory
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.log('Unable to scan directory: ' + err);
return;
}

files.forEach(file => {
if (path.extname(file) === '.txt') {
sendData(path.join(directoryPath, file));
}
});
});
1 change: 1 addition & 0 deletions packages/overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"preview": "vite preview",
"test": "vitest",
"test:ci": "vitest --coverage --reporter=junit --reporter=default --outputFile=junit.xml",
"sample": "node _fixtures/send_to_sidecar.cjs",
"yalc:publish": "yalc publish --push --sig --private"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from 'fs';
describe('SentryDataCache', () => {
// We need to refactor this to make it actually testable
test('Process Envelope', () => {
const envelope = fs.readFileSync('./_fixtures/envelope1.txt', 'utf-8');
const envelope = fs.readFileSync('./_fixtures/envelope_javascript.txt', 'utf-8');
const processedEnvelope = processEnvelope({ data: envelope, contentType: 'test' });
sentryDataCache.pushEnvelope(processedEnvelope.event);
expect(true).not.toBe(undefined);
Expand Down
2 changes: 1 addition & 1 deletion packages/overlay/src/integrations/sentry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs';

describe('Sentry Integration', () => {
test('Process Envelope', () => {
const envelope = fs.readFileSync('./_fixtures/envelope1.txt', 'utf-8');
const envelope = fs.readFileSync('./_fixtures/envelope_javascript.txt', 'utf-8');
expect(processEnvelope({ data: envelope, contentType: 'test' })).not.toBe(undefined);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function sendEnvelopesToSidecar(client: Client) {
},
mode: 'cors',
}).catch(err => {
console.error(err);
console.error(
`Sentry SDK can't connect to Sidcar is it running? See: https://spotlightjs.com/sidecar/npx/`,
err,
);
});
});
}
Expand Down
3 changes: 0 additions & 3 deletions packages/sidecar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"./vite-plugin": {
"import": "./src/vite-plugin.js"
},
"./connect": {
"import": "./src/connect.js"
},
"./run": {
"import": "./src/run.js"
}
Expand Down
34 changes: 0 additions & 34 deletions packages/sidecar/src/connect.js

This file was deleted.

0 comments on commit db73d24

Please sign in to comment.