Skip to content

Commit dea2482

Browse files
authored
Merge pull request #54 from secustor/add_unleash
Prepare for 2nd workshop
2 parents 969a3a0 + 5459fe0 commit dea2482

File tree

23 files changed

+566
-38
lines changed

23 files changed

+566
-38
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
# OpenTelemetry Frontend to Backend Demo
2+
This repo contains the example used for the `Vienna DevOps & Security` meetups.
23

3-
This repo contains the example used for the `Vienna DevOps & Security` meetup.
4+
The meetup series is build around a full example of a frontend, backend composed out of a Ingress controller, Kafka and
5+
the corresponding consumer and producer
6+
7+
![Grafana trace example](./images/trace_example.png)
8+
9+
10+
## Meetups
11+
### OpenTelemetry: from frontend to backend
412
Slides: https://docs.google.com/presentation/d/1jPDH8Csv-Qle7Z-P7rFJgjOsBpgKeehPhjFPqTRET1Y/edit?usp=sharing
513

6-
Requirements:
7-
- [Kind](https://github.com/kubernetes-sigs/kind/issues) ( node-image >1.16.x )
8-
- [Helmsman](https://github.com/Praqma/helmsman)
9-
- Docker / Buildah ( with Docker alias )
14+
### OpenTelemetry: How to debug user performance in your frontend
15+
Slides: https://docs.google.com/presentation/d/1w1VhfGQPgCAPoT2VSB6KZlXZOXa_m5p8R-xzOzzL3hM/edit?usp=sharing
16+
17+
## Usage
18+
Requirements:
19+
- [Kind](https://github.com/kubernetes-sigs/kind/issues) ( node-image >1.16.x )
20+
- [Helmsman](https://github.com/Praqma/helmsman)
21+
- Docker / Buildah ( with Docker alias )
1022

1123
This demo deploys ingresses for `*.testing.com`.
1224
To make it work you have to rewrite the DNS answers to localhost.
1325

1426
For Linux it has been as simple as adding this line to your network manager ( tested with Arch/Gnome )
1527
`echo "address=/testing.com/127.0.0.1" > /etc/NetworkManager/dnsmasq.d/testDomains.conf`
1628

17-
18-
19-
## Usage
2029
### Create Cluster
2130
To create a kind cluster and add the kubecontext to your config run `make create-kind-cluster`
2231

@@ -28,3 +37,4 @@ Build and upload the resulting images to your kind cluster
2837

2938
### Setup the environment
3039
`make prepare-environment` will setup all applications in your cluster
40+

apps/snapshot/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"react": "^16.13.1",
2424
"react-dom": "^16.13.1",
2525
"react-router-dom": "^5.1.2",
26-
"react-scripts": "3.4.1"
26+
"react-scripts": "3.4.1",
27+
"unleash-proxy-client": "^2.0.0"
2728
},
2829
"scripts": {
2930
"predeploy": "npm run build",

apps/snapshot/src/App.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import React, { Component } from "react";
1+
import React from "react";
22
import PhotoContextProvider from "./context/PhotoContext";
33
import { HashRouter, Route, Switch, Redirect } from "react-router-dom";
44
import Header from "./components/Header";
55
import Item from "./components/Item";
66
import Search from "./components/Search";
77
import NotFound from "./components/NotFound";
8+
import {BaseOpenTelemetryComponent} from "@opentelemetry/plugin-react-load";
89

9-
class App extends Component {
10+
class App extends BaseOpenTelemetryComponent {
1011
// Prevent page reload, clear input, set URL and push history on submit
1112
handleSubmit = (e, history, searchInput) => {
1213
e.preventDefault();

apps/snapshot/src/context/PhotoContext.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import React, { createContext, useState } from "react";
22
import axios from "axios";
33
import { apiKey } from "../api/config";
4-
import {tracer} from "../instrumentation";
5-
import {SpanStatusCode, context, trace} from "@opentelemetry/api";
4+
import {traceProvider} from "../instrumentation";
5+
import {SpanStatusCode} from "@opentelemetry/api";
66

77
export const PhotoContext = createContext();
88

99
const PhotoContextProvider = props => {
1010
const [images, setImages] = useState([]);
1111
const [loading, setLoading] = useState(true);
1212

13-
const runSearchTracer = tracer
13+
const runSearchTracer = traceProvider.getTracer('snapshot')
1414

1515

1616
const runSearch = query => {
17-
const testSpan = trace.getSpan(context.active())
18-
console.log(`TestSpan: ${testSpan}`)
19-
console.log(`Context:`,context.active())
20-
21-
runSearchTracer.startActiveSpan("search images",(span, query) => {
22-
runSearchTracer.startActiveSpan("query images", span => { // https://github.com/open-telemetry/opentelemetry-js/issues/1923
17+
runSearchTracer.startActiveSpan("search images",span => {
18+
runSearchTracer.startActiveSpan("query images",{}, span => { // https://github.com/open-telemetry/opentelemetry-js/issues/1923
2319
axios
2420
.get(
2521
`https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=${apiKey}&tags=${query}&per_page=24&format=json&nojsoncallback=1`

apps/snapshot/src/instrumentation.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ import * as autoInstrumentationAPI from "@opentelemetry/auto-instrumentations-we
1717
import * as api from "@opentelemetry/api";
1818
import {BaseOpenTelemetryComponent} from '@opentelemetry/plugin-react-load';
1919
import {SemanticResourceAttributes} from "@opentelemetry/semantic-conventions";
20+
import {getUnleash} from "./unleash";
21+
import {DiagConsoleLogger} from "@opentelemetry/api";
2022

2123

2224
/* Set Global Propagator */
2325
// support jaeger, W3C and W3C Baggage propagation
2426
const propagator = new CompositePropagator({propagators: [new JaegerPropagator(), new W3CTraceContextPropagator(), new W3CBaggagePropagator()]})
2527
api.propagation.setGlobalPropagator(propagator);
26-
const traceProvider = new WebTracerProvider({
28+
export const traceProvider = new WebTracerProvider({
2729
resource: new Resource({
2830
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value
2931
[SemanticResourceAttributes.SERVICE_NAME]: "snapshot",
3032
[SemanticResourceAttributes.SERVICE_NAMESPACE]: "example.meetup",
3133
[SemanticResourceAttributes.SERVICE_VERSION]: "0.1.0",
34+
[SemanticResourceAttributes.PROCESS_OWNER]: "1233"
3235
}),
3336
// this is the same as directly using the AlwaysOnSampler, but this shows how to respect the parent.
3437
// https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-core#parentbased-sampler
@@ -47,21 +50,29 @@ const traceProvider = new WebTracerProvider({
4750
// add processors
4851
traceProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
4952

50-
const exporter = new OTLPTraceExporter({
51-
url: "http://collector.testing.com/v1/traces", // url is optional and can be omitted - default is http://localhost:55681/v1/traces
52-
headers: {}, // an optional object containing custom headers to be sent with each request
53-
concurrencyLimit: 10, // an optional limit on pending requests
54-
});
55-
traceProvider.addSpanProcessor(new BatchSpanProcessor(exporter, {
56-
// The maximum queue size. After the size is reached spans are dropped.
57-
maxQueueSize: 100,
58-
// The maximum batch size of every export. It must be smaller or equal to maxQueueSize.
59-
maxExportBatchSize: 10,
60-
// The interval between two consecutive exports
61-
scheduledDelayMillis: 500,
62-
// How long the export can run before it is cancelled
63-
exportTimeoutMillis: 30000,
64-
}));
53+
getUnleash().then(value => {
54+
const exporter = new OTLPTraceExporter({
55+
url: "http://collector.testing.com/v1/traces", // url is optional and can be omitted - default is http://localhost:55681/v1/traces
56+
headers: {}, // an optional object containing custom headers to be sent with each request
57+
concurrencyLimit: 10, // an optional limit on pending requests
58+
});
59+
60+
const enabled = value.isEnabled("opentelemetry")
61+
console.log(`opentelemetry feature flag: ${enabled}`)
62+
63+
if (enabled) {
64+
traceProvider.addSpanProcessor(new BatchSpanProcessor(exporter, {
65+
// The maximum queue size. After the size is reached spans are dropped.
66+
maxQueueSize: 100,
67+
// The maximum batch size of every export. It must be smaller or equal to maxQueueSize.
68+
maxExportBatchSize: 20,
69+
// The interval between two consecutive exports
70+
scheduledDelayMillis: 500,
71+
// How long the export can run before it is cancelled
72+
exportTimeoutMillis: 30000,
73+
}));
74+
}
75+
}).catch(reason => console.log(reason))
6576

6677

6778
traceProvider.register({
@@ -83,9 +94,9 @@ registerInstrumentations({
8394
],
8495

8596
});
86-
export let tracer = traceProvider.getTracer("snapshot");
97+
8798
BaseOpenTelemetryComponent.setTracer("snapshot") // set global tracer for react
88-
BaseOpenTelemetryComponent.setLogger(traceProvider.logger)
99+
BaseOpenTelemetryComponent.setLogger(new DiagConsoleLogger())
89100

90101

91102
export default function TraceProvider({children}) {

apps/snapshot/src/unleash.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { UnleashClient } from 'unleash-proxy-client';
2+
3+
export async function getUnleash() {
4+
const unleash = new UnleashClient({
5+
url: 'http://unleash-proxy.testing.com/proxy',
6+
clientKey: 'clientKeyslkfsdklfkslfd',
7+
appName: 'default',
8+
environment: 'development'
9+
});
10+
11+
// Used to set the context fields, shared with the Unleash Proxy
12+
await unleash.updateContext({ userId: '1233' });
13+
14+
// Start the background polling
15+
await unleash.start();
16+
17+
return unleash
18+
}

apps/snapshot/yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10188,6 +10188,11 @@ timsort@^0.3.0:
1018810188
resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4"
1018910189
integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=
1019010190

10191+
tiny-emitter@^2.1.0:
10192+
version "2.1.0"
10193+
resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
10194+
integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==
10195+
1019110196
tiny-invariant@^1.0.2:
1019210197
version "1.1.0"
1019310198
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.1.0.tgz#634c5f8efdc27714b7f386c35e6760991d230875"
@@ -10413,6 +10418,14 @@ universalify@^0.1.0:
1041310418
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
1041410419
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
1041510420

10421+
unleash-proxy-client@^2.0.0:
10422+
version "2.0.0"
10423+
resolved "https://registry.yarnpkg.com/unleash-proxy-client/-/unleash-proxy-client-2.0.0.tgz#2668f949368805b4d949fdd83b121fa15daf23e9"
10424+
integrity sha512-7poi3txbSGjFG0e8QrIn4pGzw1de7xfA5YSLqu3abLs95wZ2gzuC/YTvzlt1Faol3PHTj9Tq0ov02Q7Z6nhE9g==
10425+
dependencies:
10426+
tiny-emitter "^2.1.0"
10427+
uuid "^8.3.2"
10428+
1041610429
[email protected], unpipe@~1.0.0:
1041710430
version "1.0.0"
1041810431
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
@@ -10530,6 +10543,11 @@ uuid@^3.0.1, uuid@^3.3.2:
1053010543
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
1053110544
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
1053210545

10546+
uuid@^8.3.2:
10547+
version "8.3.2"
10548+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
10549+
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
10550+
1053310551
v8-compile-cache@^2.0.3:
1053410552
version "2.1.0"
1053510553
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e"

deploy/kube-prometheus/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ grafana:
5959
# - "k8s.pod.name"
6060
# lokiSearch: true
6161

62+
- name: Jaeger
63+
access: proxy
64+
editable: false
65+
orgId: 1
66+
type: jaeger
67+
url: http://jaeger-query
68+
version: 1
69+
uid: default_jaeger
70+
jsonData:
71+
nodeGraph:
72+
enabled: true
73+
tracesToLogs:
74+
datasourceUid: default_loki
75+
# tags:
76+
# - "k8s.namespace.name"
77+
# - "k8s.pod.name"
78+
# lokiSearch: true
79+
6280
serviceMonitor:
6381
enabled: true
6482
additionalLabels:

deploy/setup.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ apps:
8181
version: 2.6.0
8282
valuesFiles:
8383
- ./unleash/values.yaml
84+
unleash-proxy:
85+
enabled: true
86+
namespace: unleash
87+
chart: ./unleash-proxy
88+
version: 0.1.0
89+
valuesFiles:
90+
- ./unleash-proxy/overwrites.yaml
8491
jaeger:
8592
enabled: true
8693
namespace: monitoring

deploy/unleash-proxy/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

0 commit comments

Comments
 (0)