This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Tracer } from './tracer'; | |
import express, { Request, Response } from 'express'; | |
import { ErrorHandler, Handler, wrap } from 'async-middleware'; | |
import { spanProcessor } from './span-processor'; | |
import { SpanOptions } from '@opentelemetry/api'; | |
async function main() { | |
const tracer = new Tracer({ name: 'example-tracer-node' }); | |
const app = express(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pg from 'pg'; | |
async function main() { | |
const client = new pg.Client({ | |
host: '127.0.0.1', | |
port: 5432, | |
user: 'username', | |
password: 'password', | |
database: 'test' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Deferred<T> = { | |
resolve: (value: T) => void; | |
reject: (reason?: any) => void; | |
promise: Promise<T>; | |
} | |
// Call function when timeout is reached | |
// by splitin array of arguments into batches | |
// and calling function with each batch | |
// Allow setup maxParallel to limit number of parallel calls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CreateBucketCommand, DeleteBucketCommand, DeleteObjectCommand, ListBucketsCommand, ListObjectsCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'; | |
import pg from 'pg'; | |
import QueryStream from 'pg-query-stream' | |
import { JsonStreamStringify } from 'json-stream-stringify'; | |
/** | |
* This is an example of streaming data from a postgresql database to S3 | |
* with low memory usage | |
*/ | |
async function main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { context, trace } from "@opentelemetry/api"; | |
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks"; | |
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base"; | |
import { promisify } from "util"; | |
async function main() { | |
const contextManager = new AsyncLocalStorageContextManager(); | |
const provider = new BasicTracerProvider(); | |
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from "express"; | |
import bodyParser from "body-parser"; | |
import { trace, context } from "@opentelemetry/api"; | |
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base"; | |
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks'; | |
const provider = new BasicTracerProvider(); | |
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); | |
trace.setGlobalTracerProvider(provider); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspector from 'inspector'; | |
import { writeFile } from 'fs/promises'; | |
import cron from 'node-cron'; | |
class Profiler { | |
private session: inspector.Session; | |
constructor() { | |
this.session = new inspector.Session(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function register(message) { | |
await import(message.path); | |
process.send({ type: 'registred' }); | |
} | |
process.on('message', (message) => { | |
switch (message.type) { | |
case 'register': | |
return register(message); | |
case 'ping': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typeorm from 'typeorm'; | |
async function main() { | |
const dataSource = new typeorm.DataSource({ | |
type: 'postgres', | |
host: '127.0.0.1', | |
username: 'username', | |
password: 'password', | |
database: 'test', | |
extra: /**@type {import('pg').PoolConfig}*/({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function main() { | |
const pg = require('pg'); | |
const client = new pg.Client({ | |
user: 'admin', | |
password: 'admin', | |
database: 'test', | |
host: '127.0.0.1', | |
port: 5432 | |
}); |