Skip to content

Commit

Permalink
Update README and add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Oct 6, 2023
1 parent c408089 commit e605459
Show file tree
Hide file tree
Showing 15 changed files with 2,193 additions and 68 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/*.js
**/*.d.ts
node_modules/**
example/**
5 changes: 0 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
"extends": [
"@myrotvorets/myrotvorets-ts"
],
"rules": {
"jest/no-commented-out-tests": "off",
"jest/no-done-callback": "off",
"jest/valid-expect": "off"
},
"env": {
"node": true,
"jest": false,
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/build-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build and Test Sample Code

on:
push:
branches:
- '**'
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[ci skip]') || github.event_name == 'workflow_dispatch' }}
strategy:
fail-fast: false
matrix:
node:
- 'current'
- 'lts/*'
- 'lts/-1'
name: Build and test (Node ${{ matrix.node }})
steps:
- name: Prepare the source
uses: myrotvorets/composite-actions/build-test-nodejs@master
with:
node-version: ${{ matrix.node }}
run-tests: no

- name: Install dependencies (example)
run: npm ci
working-directory: example

- name: Build
run: npm run build && (cd example && npm run build)

- name: Smoke test
run: npx ts-node src/index.ts
working-directory: example
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[ci skip]') || github.event_name == 'workflow_dispatch' }}
steps:
- name: Run cose style check
- name: Run code style check
uses: myrotvorets/composite-actions/node-run-script@master
with:
script: lint
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/.vscode
/coverage
/dist
/node_modules
node_modules
/test-report.xml
34 changes: 9 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,22 @@

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=myrotvorets_opentelemetry-plugin-knex&metric=alert_status)](https://sonarcloud.io/dashboard?id=myrotvorets_opentelemetry-plugin-knex)
[![Build and Test](https://github.com/myrotvorets/opentelemetry-plugin-knex/actions/workflows/build.yml/badge.svg)](https://github.com/myrotvorets/opentelemetry-plugin-knex/actions/workflows/build.yml)
[![codebeat badge](https://codebeat.co/badges/94fbbee4-e589-4c17-8a0d-bed6be1dcd86)](https://codebeat.co/projects/github-com-myrotvorets-opentelemetry-plugin-knex-master)

OpenTelemetry knex automatic instrumentation package

## Usage

```typescript
import opentelemetry from '@opentelemetry/api';
import { NodeTracerProvider } from '@opentelemetry/node';
import { SimpleSpanProcessor } from '@opentelemetry/tracing';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { KnexInstrumentation } from '@myrotvorets/opentelemetry-plugin-knex';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';

const provider = new NodeTracerProvider({
plugins: {
knex: {
path: '@myrotvorets/opentelemetry-plugin-knex',
},
// Add other plugins as needed
http: {},
https: {},
},
const sdk = new NodeSDK({
serviceName: 'example',
instrumentations: [new HttpInstrumentation(), new KnexInstrumentation()],
});

// Add exporters as needed
const zipkinExporter = new ZipkinExporter({
url: process.env.ZIPKIN_ENDPOINT,
serviceName: 'my-service',
});

const zipkinProcessor = new SimpleSpanProcessor(zipkinExporter);
provider.addSpanProcessor(zipkinProcessor);

// Go!
provider.register();
sdk.start();
```

See the `example` directory for a working example.
6 changes: 6 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# opentelemetry-plugin-knex Usage Example

```sh
docker run -it --rm -d -p 9411:9411 openzipkin/zipkin
OTEL_BSP_SCHEDULE_DELAY=0 OTEL_TRACES_EXPORTER=zipkin npx ts-node src/index.ts
```
Loading

0 comments on commit e605459

Please sign in to comment.