Skip to content

Commit

Permalink
Move the vendor stuff into the package
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Aug 23, 2023
1 parent 5ca3e27 commit d0448c3
Show file tree
Hide file tree
Showing 381 changed files with 87 additions and 18,685 deletions.
22 changes: 3 additions & 19 deletions packages/lib/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
# `@autometrics/autometrics` 📈✨
# `autometrics` 📈✨

## Documentation

Full documentation for `@autometrics/autometrics` library can be found
Full documentation for the `autometrics` library can be found
[here](https://github.com/autometrics-dev/autometrics-ts).

## Installation: autometrics and peer dependencies

```shell
# npm
npm install @autometrics/autometrics @opentelemetry/sdk-metrics
@opentelemetry/exporter-prometheus

# yarn
yarn add @autometrics/autometrics @opentelemetry/sdk-metrics
@opentelemetry/exporter-prometheus

# pnpm
pnpm add @autometrics/autometrics @opentelemetry/sdk-metrics
@opentelemetry/exporter-prometheus
```

## Basic example

```typescript
import { autometrics } from "@autometrics/autometrics";
import { autometrics } from "https://deno.land/x/autometrics";

async function createUser(payload: User) {
// ...
Expand Down
35 changes: 35 additions & 0 deletions packages/lib/README.node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# `@autometrics/autometrics` 📈✨

## Documentation

Full documentation for the `@autometrics/autometrics` library can be found
[here](https://github.com/autometrics-dev/autometrics-ts).

## Installation: autometrics and peer dependencies

```shell
# npm
npm install @autometrics/autometrics @opentelemetry/sdk-metrics
@opentelemetry/exporter-prometheus

# yarn
yarn add @autometrics/autometrics @opentelemetry/sdk-metrics
@opentelemetry/exporter-prometheus

# pnpm
pnpm add @autometrics/autometrics @opentelemetry/sdk-metrics
@opentelemetry/exporter-prometheus
```

## Basic example

```typescript
import { autometrics } from "@autometrics/autometrics";

async function createUser(payload: User) {
// ...
}

const user = autometrics(createUser);
// ^ instrumented function
```
4 changes: 2 additions & 2 deletions packages/lib/buildInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { otelApi } from "./deps.ts";
import type { UpDownCounter } from "./vendor/opentelemetry-api/mod.ts";

import { BUILD_INFO_DESCRIPTION, BUILD_INFO_NAME } from "./constants.ts";
import { getBranch, getCommit, getVersion } from "./platform.deno.ts";
Expand Down Expand Up @@ -46,7 +46,7 @@ export type BuildInfo = {
* @internal
*/
export let buildInfo: BuildInfo = {};
let buildInfoGauge: otelApi.UpDownCounter;
let buildInfoGauge: UpDownCounter;

/**
* Records the build info for the application.
Expand Down
6 changes: 0 additions & 6 deletions packages/lib/deps.ts

This file was deleted.

18 changes: 10 additions & 8 deletions packages/lib/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { BuildInfo, buildInfo, recordBuildInfo } from "./buildInfo.ts";
import { HISTOGRAM_NAME } from "./constants.ts";
import { otelExporterPrometheus, otelSdkMetrics } from "./deps.ts";

const { PrometheusExporter, PrometheusSerializer } = otelExporterPrometheus;
const {
import {
PrometheusExporter,
PrometheusSerializer,
} from "./vendor/opentelemetry-exporter-prometheus/mod.ts";
import {
AggregationTemporality,
ExplicitBucketHistogramAggregation,
InMemoryMetricExporter,
MetricReader,
MeterProvider,
PeriodicExportingMetricReader,
View,
} = otelSdkMetrics;
} from "./vendor/opentelemetry-sdk-metrics/mod.ts";

let globalShouldEagerlyPush = false;
let pushMetrics = () => {};
let autometricsMeterProvider: otelSdkMetrics.MeterProvider;
let exporter: otelSdkMetrics.MetricReader;
let autometricsMeterProvider: MeterProvider;
let exporter: MetricReader;

type Exporter = otelSdkMetrics.MetricReader;
type Exporter = MetricReader;

/**
* @group Initialization API
Expand Down
10 changes: 7 additions & 3 deletions packages/lib/tests/buildInfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {
AggregationTemporality,
InMemoryMetricExporter,
PeriodicExportingMetricReader,
} from "../vendor/opentelemetry-sdk-metrics/mod.ts";
import { assertMatch } from "./deps.ts";
import { collectAndSerialize } from "./util.ts";
import { getMetricsProvider } from "../instrumentation.ts";
import { init } from "../instrumentation.ts";
import { otelSdkMetrics } from "../deps.ts";

const buildInfo = {
version: "1.0.0",
Expand All @@ -11,8 +15,8 @@ const buildInfo = {
};

/*Deno.test("Autometrics build info tests", async (t) => {
const exporter = new otelSdkMetrics.PeriodicExportingMetricReader({
exporter: new otelSdkMetrics.InMemoryMetricExporter(otelSdkMetrics.AggregationTemporality.DELTA),
const exporter = new PeriodicExportingMetricReader({
exporter: new InMemoryMetricExporter(AggregationTemporality.DELTA),
});
init({ buildInfo, exporter });
Expand Down
9 changes: 6 additions & 3 deletions packages/lib/tests/concurrency.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { otelSdkMetrics } from "../deps.ts";
import {
InMemoryMetricExporter,
PeriodicExportingMetricReader,
} from "../vendor/opentelemetry-sdk-metrics/mod.ts";
import { assertMatch } from "./deps.ts";
import { autometrics, init } from "../mod.ts";
import { collectAndSerialize } from "./util.ts";
import { getMetricsProvider } from "../instrumentation.ts";

/*Deno.test("Autometrics concurrency tests", async (t) => {
const exporter = new otelSdkMetrics.PeriodicExportingMetricReader({
const exporter = new PeriodicExportingMetricReader({
// 0 - using delta aggregation temporality setting
// to ensure data submitted to the gateway is accurate
exporter: new otelSdkMetrics.InMemoryMetricExporter(0),
exporter: new InMemoryMetricExporter(0),
});
init({ exporter });
Expand Down
10 changes: 7 additions & 3 deletions packages/lib/tests/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import {
AggregationTemporality,
InMemoryMetricExporter,
PeriodicExportingMetricReader,
} from "../vendor/opentelemetry-sdk-metrics/mod.ts";
import { Autometrics, autometrics, init } from "../mod.ts";
import { assertMatch, assertRejects } from "./deps.ts";
import { collectAndSerialize } from "./util.ts";
import { getMetricsProvider } from "../instrumentation.ts";
import { otelSdkMetrics } from "../deps.ts";

/*Deno.test("Autometrics integration test", async (t) => {
const exporter = new otelSdkMetrics.PeriodicExportingMetricReader({
const exporter = new PeriodicExportingMetricReader({
// 0 - using delta aggregation temporality setting
// to ensure data submitted to the gateway is accurate
exporter: new otelSdkMetrics.InMemoryMetricExporter(otelSdkMetrics.AggregationTemporality.DELTA),
exporter: new InMemoryMetricExporter(AggregationTemporality.DELTA),
});
init({ exporter });
Expand Down
9 changes: 6 additions & 3 deletions packages/lib/tests/objectives.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
InMemoryMetricExporter,
PeriodicExportingMetricReader,
} from "../vendor/opentelemetry-sdk-metrics/mod.ts";
import { assertMatch } from "./deps.ts";
import {
autometrics,
Expand All @@ -7,13 +11,12 @@ import {
} from "../mod.ts";
import { collectAndSerialize } from "./util.ts";
import { getMetricsProvider } from "../instrumentation.ts";
import { otelSdkMetrics } from "../deps.ts";

/*Deno.test("Autometrics objectives test", async (t) => {
const exporter = new otelSdkMetrics.PeriodicExportingMetricReader({
const exporter = new PeriodicExportingMetricReader({
// 0 - using delta aggregation temporality setting
// to ensure data submitted to the gateway is accurate
exporter: new otelSdkMetrics.InMemoryMetricExporter(0),
exporter: new InMemoryMetricExporter(0),
});
init({ exporter });
Expand Down
9 changes: 4 additions & 5 deletions packages/lib/tests/util.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { otelExporterPrometheus, otelSdkMetrics } from "../deps.ts";
import { PeriodicExportingMetricReader } from "../vendor/opentelemetry-sdk-metrics/mod.ts";
import { PrometheusSerializer } from "../vendor/opentelemetry-exporter-prometheus/mod.ts";

export async function collectAndSerialize(
exporter: otelSdkMetrics.PeriodicExportingMetricReader,
exporter: PeriodicExportingMetricReader,
) {
const response = await exporter.collect();

return new otelExporterPrometheus.PrometheusSerializer().serialize(
response.resourceMetrics,
);
return new PrometheusSerializer().serialize(response.resourceMetrics);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/lib/wrappers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { otelApi } from "./deps.ts";
import type { Attributes } from "./vendor/opentelemetry-api/mod.ts";
import { setBuildInfo } from "./buildInfo.ts";
import {
COUNTER_DESCRIPTION,
Expand Down Expand Up @@ -216,8 +216,8 @@ export function autometrics<F extends FunctionSig>(
return fn as F;
}

const counterObjectiveAttributes: otelApi.Attributes = {};
const histogramObjectiveAttributes: otelApi.Attributes = {};
const counterObjectiveAttributes: Attributes = {};
const histogramObjectiveAttributes: Attributes = {};

// NOTE - Gravel Gateway will reject two metrics of the same name if one of them has a subset of the attributes of the other
// This means to be able to support functions that have objectives, as well as functions that don't, we need to
Expand Down
16 changes: 4 additions & 12 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,16 @@ for (const [dir, name] of Object.entries(packages)) {
},
mappings: {
"./packages/lib/platform.deno.ts": "./packages/lib/platform.node.ts",
"./vendor/opentelemetry-api/mod.ts": {
"./packages/lib/vendor/opentelemetry-api/mod.ts": {
name: "@opentelemetry/api",
peerDependency: true,
version: "^1.4.0",
},
"./vendor/opentelemetry-core/mod.ts": {
name: "@opentelemetry/core",
version: "^1.15.0",
},
"./vendor/opentelemetry-exporter-prometheus/mod.ts": {
"./packages/lib/vendor/opentelemetry-exporter-prometheus/mod.ts": {
name: "@opentelemetry/exporter-prometheus",
version: "^0.41.0",
},
"./vendor/opentelemetry-resources/mod.ts": {
name: "@opentelemetry/resources",
version: "^1.15.0",
},
"./vendor/opentelemetry-sdk-metrics/mod.ts": {
"./packages/lib/vendor/opentelemetry-sdk-metrics/mod.ts": {
name: "@opentelemetry/sdk-metrics",
version: "^1.15.0",
},
Expand All @@ -83,7 +75,7 @@ for (const [dir, name] of Object.entries(packages)) {
// steps to run after building and before running the tests
Deno.copyFileSync("LICENSE", `${OUT_DIR}/${dir}/LICENSE`);
Deno.copyFileSync(
`packages/${dir}/README.md`,
`packages/${dir}/README.node.md`,
`${OUT_DIR}/${dir}/README.md`,
);
},
Expand Down
Loading

0 comments on commit d0448c3

Please sign in to comment.