Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Sentry = require('@sentry/node');
const postgres = require('postgres');
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);
Expand All @@ -14,6 +15,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
await sql`
CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Sentry from '@sentry/node';
import { createRequire } from 'node:module';
import postgres from 'postgres';

const require = createRequire(import.meta.url);
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

Expand All @@ -14,6 +18,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
await sql`
CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sentry.init({

// Import postgres AFTER Sentry.init() so instrumentation is set up
const postgres = require('postgres');
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);
Expand All @@ -25,6 +26,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
// Test sql.unsafe() - this was not being instrumented before the fix
await sql.unsafe('CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Sentry from '@sentry/node';
import { createRequire } from 'node:module';
import postgres from 'postgres';

const require = createRequire(import.meta.url);
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

Expand All @@ -15,6 +19,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
// Test sql.unsafe() - this was not being instrumented before the fix
await sql.unsafe('CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sentry.init({

// Import postgres AFTER Sentry.init() so instrumentation is set up
const postgres = require('postgres');
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);
Expand All @@ -25,6 +26,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
await sql`
CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Sentry from '@sentry/node';
import { createRequire } from 'node:module';
import postgres from 'postgres';

const require = createRequire(import.meta.url);
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

Expand All @@ -15,6 +19,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
await sql`
CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
const Sentry = require('@sentry/node');
const { waitForPostgres } = require('./wait-for-postgres.js');

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
Expand All @@ -23,6 +24,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
await sql`
CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Sentry from '@sentry/node';
import { createRequire } from 'node:module';
import postgres from 'postgres';

const require = createRequire(import.meta.url);
const { waitForPostgres } = require('./wait-for-postgres.js');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

Expand All @@ -14,6 +18,7 @@ async function run() {
},
async () => {
try {
await waitForPostgres(sql);
await sql`
CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"));
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

/**
* Retries until Postgres accepts connections. `docker compose up --wait` can report healthy
* before the port forward on the host is ready (flaky on busy CI).
*/
async function waitForPostgres(sql, maxWaitMs = 60_000) {
const deadline = Date.now() + maxWaitMs;
for (;;) {
try {
await sql`SELECT 1`;
return;
} catch {
if (Date.now() > deadline) {
throw new Error('Timed out waiting for Postgres to accept connections');
}
await new Promise(r => setTimeout(r, 250));
}
}
}

module.exports = { waitForPostgres };
Loading