Skip to content

Commit 1d39f4f

Browse files
committed
Add example
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 18f0736 commit 1d39f4f

20 files changed

+1808
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
/spec/reports/
88
/tmp/
99

10+
/example/node_modules/
11+
1012
Gemfile.lock

example/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Fluentd Observability Demo
2+
3+
This is demo based on [fluent-bit-observability-demo](https://github.com/fluent/fluent-bit-observability-demo)
4+
for using Fluentd to export OpenTelemetry traces and metrics.
5+
6+
The telemetry data have been provided by js application in `app` directory.
7+
8+
* metrics.js: OpenTelemetry instrumented application that exports metrics to an endpoint (Fluentd) using the otlp protocol
9+
* tracing.js: OpenTelemetry instrumented application that exports trace data to an endpoint (Fluentd) using the otlp protocol
10+
11+
### Setup
12+
13+
1. Run `docker-compose up -d --build` to start the application
14+
15+
### Visualize metrics data
16+
17+
1. Go to [`localhost:3000`](http://localhost:3000) and login to Grafana using credentials admin, admin
18+
19+
2. Then, show `demo > Basic Service Trace` in [dashboard](http://localhost:3000/dashboards).
20+
21+
![dashboard](./assets/dashboard.png)
22+
23+
24+
### Visualize trace data
25+
26+
1. Navigate to [`localhost:16686`](http://localhost:16686/), select the correct service and find traces.
27+
28+
![find-traces](./assets/find-traces.png)
29+
30+
31+
![trace-data](./assets/trace-data.png)
32+

example/app/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:22
2+
WORKDIR /usr/src/app
3+
COPY package*.json ./
4+
RUN npm install
5+
COPY . .
6+
CMD ["/bin/bash", "-c", "node tracing.js & node metrics.js"]

example/app/metrics.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Copyright (C) 2022 The Fluent Bit authors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api');
19+
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto');
20+
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics-base');
21+
const { Resource } = require('@opentelemetry/resources');
22+
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
23+
24+
// Optional and only needed to see the internal diagnostic logging (during development)
25+
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
26+
27+
const metricExporter = new OTLPMetricExporter({'url':'http://fluentd:4318/v1/metrics'});
28+
29+
const meterProvider = new MeterProvider({
30+
resource: new Resource({
31+
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
32+
}),
33+
});
34+
35+
meterProvider.addMetricReader(new PeriodicExportingMetricReader({
36+
exporter: metricExporter,
37+
exportIntervalMillis: 1000,
38+
}));
39+
40+
const meter = meterProvider.getMeter('example-exporter-collector');
41+
42+
const requestCounter = meter.createCounter('requests', {
43+
description: 'Example of a Counter',
44+
});
45+
46+
const upDownCounter = meter.createUpDownCounter('test_up_down_counter', {
47+
description: 'Example of a UpDownCounter',
48+
});
49+
50+
const attributes = { pid: process.pid, environment: 'staging' };
51+
52+
setInterval(() => {
53+
requestCounter.add(15, attributes);
54+
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes);
55+
}, 1000);

0 commit comments

Comments
 (0)