Skip to content

Commit

Permalink
add metadata generation
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Jan 10, 2024
1 parent 1983346 commit db3c998
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ jobs:
run: npm ci
- name: Build
run: npm run compile
- name: Generate metadata YAML
run: node scripts/generate-metadata-yaml.js > splunk-otel-js-metadata.yaml
- name: Upload metadata yaml
uses: actions/upload-artifact@v3
with:
name: splunk-otel-js-metadata.yaml
path: splunk-otel-js-metadata.yaml

centos-build-check:
runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions docs/advanced-config.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
> The official Splunk documentation for this page is [Configure the Splunk Distribution of OTel JS](https://quickdraw.splunk.com/redirect/?product=Observability&version=current&location=nodejs.application.config).
>
> The official Splunk documentation for this page is [Configure the Splunk Distribution of OTel JS](https://quickdraw.splunk.com/redirect/?product=Observability&version=current&location=nodejs.application.config).
>
> For instructions on how to contribute to the docs, see [CONTRIBUTING.md](../CONTRIBUTING.md#documentation).
# Advanced Configuration
Expand Down Expand Up @@ -55,15 +55,15 @@ This distribution supports all the configuration options supported by the compon
| --------------------------------------------------------------- | ----------------------- | ------- | ---
| `OTEL_ATTRIBUTE_COUNT_LIMIT` | | Stable | Maximum allowed span attribute count
| `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` | `12000`\* | Stable | Maximum allowed attribute value size
| `OTEL_EXPORTER_OTLP_ENDPOINT`<br>`endpoint` | `http://localhost:4317` | Stable | The OTLP endpoint to export to. Only OTLP over gRPC is supported.
| `OTEL_EXPORTER_OTLP_ENDPOINT`<br>`endpoint` | `http://localhost:4317` | Stable | The OTLP endpoint to export to.
| `OTEL_LOG_LEVEL` | | Stable | Log level to use in diagnostics logging. **Does not set the logger.**
| `OTEL_PROPAGATORS`<br>`tracing.propagators` | `tracecontext,baggage` | Stable | Comma-delimited list of propagators to use. Valid keys: `baggage`, `tracecontext`, `b3multi`, `b3`.
| `OTEL_RESOURCE_ATTRIBUTES` | | Stable | Comma-separated list of resource attributes added to every reported span. <details><summary>Example</summary>`key1=val1,key2=val2`</details>
| `OTEL_SERVICE_NAME`<br>`serviceName` | `unnamed-node-service` | Stable | The service name of this Node service.
| `OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT` | `128` | Stable | Maximum allowed span attribute count
| `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | | Stable | Maximum allowed attribute value size. Empty value is treated as infinity
| `OTEL_SPAN_EVENT_COUNT_LIMIT` | `128` | Stable |
| `OTEL_SPAN_LINK_COUNT_LIMIT` | `1000`\* | Stable |
| `OTEL_SPAN_EVENT_COUNT_LIMIT` | `128` | Stable |
| `OTEL_SPAN_LINK_COUNT_LIMIT` | `1000`\* | Stable |
| `OTEL_TRACES_EXPORTER`<br>`tracing.spanExporterFactory` | `otlp` | Stable | Chooses the trace exporters. Shortcut for setting `spanExporterFactory`. Comma-delimited list of exporters. Currently supported values: `otlp`, `console`.
| `OTEL_TRACES_SAMPLER` | `parentbased_always_on` | Stable | Sampler to be used for traces. See [Sampling](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampling)
| `OTEL_TRACES_SAMPLER_ARG` | | Stable | String value to be used as the sampler argument. Only be used if OTEL_TRACES_SAMPLER is set.
Expand Down
177 changes: 177 additions & 0 deletions scripts/generate-metadata-yaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
const { join } = require("path");
const { readFile } = require("node:fs/promises");

const { getInstrumentations } = require('../lib/instrumentations');

const LOADED_INSTRUMENTATIONS = getInstrumentations();

const KNOWN_TARGET_LIBRARY_VERSIONS = new Map([
["splunk-opentelemetry-instrumentation-elasticsearch", [">=5 <8"]],
["splunk-opentelemetry-instrumentation-kafkajs", ["*"]],
["splunk-opentelemetry-instrumentation-sequelize", ["*"]],
["splunk-opentelemetry-instrumentation-typeorm", [">0.2.28"]],
["@opentelemetry/instrumentation-dns", ["*"]],
["@opentelemetry/instrumentation-net", ["*"]],
["@opentelemetry/instrumentation-http", ["*"]],
["@opentelemetry/instrumentation-grpc", ["1.x"]],
["@opentelemetry/instrumentation-aws-sdk", ["2.x", "3.x"]],
["@opentelemetry/instrumentation-redis", ["^2.6.0", "3.x"]],
["@opentelemetry/instrumentation-redis-4", ["4.x"]]
]);

const INSTRUMENTATIONS = [
{ name: "@opentelemetry/instrumentation-amqplib", target: "amqplib", },
{ name: "@opentelemetry/instrumentation-aws-sdk", target: "aws-sdk and @aws-sdk", },
{ name: "@opentelemetry/instrumentation-bunyan", target: "bunyan", },
{ name: "@opentelemetry/instrumentation-cassandra-driver", target: "cassandra-driver", },
{ name: "@opentelemetry/instrumentation-connect", target: "connect", },
{ name: "@opentelemetry/instrumentation-dataloader", target: "dataloader", },
{ name: "@opentelemetry/instrumentation-dns", target: "dns", },
{ name: "@opentelemetry/instrumentation-express", target: "express", },
{ name: "@opentelemetry/instrumentation-fastify", target: "fastify", },
{ name: "@opentelemetry/instrumentation-generic-pool", target: "generic-pool", },
{ name: "@opentelemetry/instrumentation-graphql", target: "graphql", },
{ name: "@opentelemetry/instrumentation-grpc", target: "@grpc/grpc-js", },
{ name: "@opentelemetry/instrumentation-hapi", target: "hapi", },
{ name: "@opentelemetry/instrumentation-http", target: "http", },
{ name: "@opentelemetry/instrumentation-ioredis", target: "ioredis", },
{ name: "@opentelemetry/instrumentation-knex", target: "knex", },
{ name: "@opentelemetry/instrumentation-koa", target: "koa", },
{ name: "@opentelemetry/instrumentation-memcached", target: "memcached", },
{ name: "@opentelemetry/instrumentation-mongodb", target: "mongodb", },
{ name: "@opentelemetry/instrumentation-mongoose", target: "mongoose", },
{ name: "@opentelemetry/instrumentation-mysql", target: "mysql", },
{ name: "@opentelemetry/instrumentation-mysql2", target: "mysql2", },
{ name: "@opentelemetry/instrumentation-nestjs-core", target: "@nestjs/core", },
{ name: "@opentelemetry/instrumentation-net", target: "net", },
{ name: "@opentelemetry/instrumentation-pg", target: "pg", },
{ name: "@opentelemetry/instrumentation-pino", target: "pino", },
{ name: "@opentelemetry/instrumentation-redis", target: "redis", },
{ name: "@opentelemetry/instrumentation-redis-4", target: "redis", },
{ name: "@opentelemetry/instrumentation-restify", target: "restify", },
{ name: "@opentelemetry/instrumentation-router", target: "router", },
{ name: "@opentelemetry/instrumentation-tedious", target: "tedious", },
{ name: "@opentelemetry/instrumentation-winston", target: "winston", },
{ name: "splunk-opentelemetry-instrumentation-elasticsearch", target: "@elastic/elasticsearch", support: "supported", },
{ name: "splunk-opentelemetry-instrumentation-kafkajs", target: "kafkajs", support: "supported", },
{ name: "splunk-opentelemetry-instrumentation-sequelize", target: "sequelize", support: "supported", },
{ name: "splunk-opentelemetry-instrumentation-typeorm", target: "typeorm", support: "supported", },
];

async function getSupportedVersion(instrumentation) {
const name = instrumentation.instrumentationName;

const versions = KNOWN_TARGET_LIBRARY_VERSIONS.get(name);

if (versions !== undefined) {
return versions;
}

return await readMeVersions(name);
}

function isSpace(s) {
return s === " " || s === "\t" || s === "\n" || s === "\r";
}

async function readMeVersions(instrumentationName) {
const path = require.resolve(instrumentationName);
const readmePath = join(path, "../../../README.md");

const readMe = (await readFile(readmePath, { encoding: "utf8" })).toLowerCase();

const supportedVersionsHeader = "# supported versions";
let loc = readMe.indexOf(supportedVersionsHeader);

if (loc === -1) {
throw new Error(`Versions not found for ${instrumentationName}`);
}

loc += supportedVersionsHeader.length;

let token = readMe.charAt(loc);

while (isSpace(token)) {
loc += 1;
token = readMe.charAt(loc);
}

const nextHashLoc = readMe.indexOf("#", loc);

return versionLines = readMe
.substring(loc, nextHashLoc)
.split("\n")
.filter(s => s.length > 0)
.map((s) => {
return s.replaceAll("`", "").replaceAll("`", "").replace("- ", "");
});
}

async function getSupportedLibraryVersions(instrumentations) {
const versions = await Promise.all(instrumentations.map(i => getSupportedVersion(i)));

const versionsByInstrumentation = {};

versions.forEach((v, i) => {
versionsByInstrumentation[instrumentations[i].instrumentationName] = v;
});

return versionsByInstrumentation;
}

function getSettingsList() {
const { listEnvVars } = require("../lib");
return listEnvVars();
}

function populateSettings(lines) {
const settings = getSettingsList();
lines.push("settings:");

function addSetting(setting) {
lines.push(`- name: ${setting.name}`);
lines.push(` description: ${setting.description}`);
lines.push(` default: ${setting.default}`);
lines.push(` type: ${setting.type}`);
lines.push(` category: ${setting.category}`);
}

for (const setting of settings) {
addSetting(setting);
}

return lines;
}

async function populateInstrumentations(lines) {
const versions = await getSupportedLibraryVersions(LOADED_INSTRUMENTATIONS);

for (const instrumentation of INSTRUMENTATIONS) {
lines.push(
"- keys:",
` - "${instrumentation.name}"`,
" instrumented_components:",
` - name: "${instrumentation.target}"`,
` supported_versions: "${versions[instrumentation.name]}"`,
` support: ${instrumentation.support ?? "community"}`,
);
}

return lines;
}

async function genMetadata() {
let lines = [
"component: Splunk Distribution of OpenTelemetry JavaScript",
`version: ${require("../package.json").version}`,
];

lines = populateSettings(lines);
lines = await populateInstrumentations(lines);

const yaml = lines.join("\n");
process.stdout.write(yaml);
process.stdout.write("\n");
}

genMetadata();
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
} from './metrics/ConsoleMetricExporter';
import { startProfiling as _startProfiling } from './profiling';
export { start, stop } from './start';
export { listEnvVars } from './utils';

export const startMetrics = deprecate(
_startMetrics,
Expand Down
Loading

0 comments on commit db3c998

Please sign in to comment.