-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: browser support for exporter-trace-otlp-proto #3208
Merged
legendecas
merged 51 commits into
open-telemetry:main
from
pkanal:proto-exporter-browser
Jan 20, 2023
Merged
Changes from 9 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
915ce52
add node & browser platform for exporter-trace-otlp-proto
pkanal 87327f0
add browser support for proto base exporter
pkanal b7c8c19
add base browser class with xhr support
pkanal 1fec3b3
add browser class for proto trace exporter
pkanal 4214129
slight tweaks to make it work
pkanal d33f9bb
send data as blob to avoid making sync xhr requests
pkanal 3dd4e17
fix lint
pkanal 35c193f
remove console.logs and add browser proto example
pkanal 5ed212d
cleanup and start adding tests
pkanal 933d37e
Merge branch 'main' of github.com:pkanal/opentelemetry-js into proto-…
scheler 9953561
Undo formatting changes
scheler 5e87c85
exporter-trace-otlp-proto: fix compile errors
scheler 1616d2b
Misc updates from review comments
scheler e3043b0
Merge branch 'main' of github.com:pkanal/opentelemetry-js into proto-…
scheler 0020c98
Adding changelog entry
scheler 6125ec2
Merge branch 'open-telemetry:main' into proto-exporter-browser
scheler c420fd0
Reverting format changes not needed
scheler f260db8
Merge branch 'main' into proto-exporter-browser
legendecas fb6cfd2
Merge branch 'open-telemetry:main' into proto-exporter-browser
scheler 3d9ae04
Moving the send function into the class for browser case.
scheler 46b665a
Merge branch 'main' into proto-exporter-browser
scheler 2000c41
Adjust indentation to fix lint errors
scheler 6366e4b
Remove template parameter that's not needed
scheler 50e1af0
Apply review changes
scheler 302e09c
Merge branch 'main' into proto-exporter-browser
scheler a16fcf5
fix the import path
scheler 266d293
Addressing lint errors
scheler 4cd39c0
Merge branch 'main' into proto-exporter-browser
scheler ed1835e
Merge branch 'open-telemetry:main' into proto-exporter-browser
scheler 84be752
Explicit imports for browser case
scheler d92f5fe
More explicit exports
scheler 61c7be7
Add missing exports
scheler 3eed4bb
Address lint issues with export statements
scheler c618265
Adding missing exports
scheler cbabbf1
Adding missing export
scheler 519fa7c
Using import from top level folder
scheler 5f67e56
Merge branch 'open-telemetry:main' into proto-exporter-browser
scheler ad2aa0e
Trigger Build
scheler e57f0f2
Merge branch 'proto-exporter-browser' of github.com:pkanal/openteleme…
scheler b26fd7f
Merge branch 'main' into proto-exporter-browser
pichlermarc f421989
Update experimental/packages/exporter-trace-otlp-proto/test/browser/C…
scheler 8064d5b
Remove trailing comma
scheler 2678ff3
Remove blank line to fix lint error
scheler c898ea2
Fixes based on testing opentelemetry-web/fetch-proto
scheler d48503a
Add additional missing export
scheler a800550
Skip hex conversion of traceId for the protobuf
scheler 598bc56
Add esm/esnext builds for the proto packages
scheler 5596d13
Merge branch 'main' into proto-exporter-browser
scheler 1788269
Merge branch 'main' into proto-exporter-browser
legendecas 2e0c4ec
Merge branch 'main' into proto-exporter-browser
scheler 9429864
Trigger Build
scheler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
examples/opentelemetry-web/examples/fetchProtoExporter/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to call this folder |
||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Fetch Plugin Example</title> | ||
<base href="/"> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
|
||
<body> | ||
Example of using Web Tracer with Fetch plugin with console exporter and proto exporter | ||
<script type="text/javascript" src="fetchProtoExporter.js"></script> | ||
<br/> | ||
<button id="button1">Test</button> | ||
|
||
</body> | ||
|
||
</html> |
97 changes: 97 additions & 0 deletions
97
examples/opentelemetry-web/examples/fetchProtoExporter/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const { context, trace } = require("@opentelemetry/api"); | ||
const { | ||
ConsoleSpanExporter, | ||
SimpleSpanProcessor, | ||
} = require("@opentelemetry/sdk-trace-base"); | ||
const { WebTracerProvider } = require("@opentelemetry/sdk-trace-web"); | ||
const { | ||
FetchInstrumentation, | ||
} = require("@opentelemetry/instrumentation-fetch"); | ||
const { ZoneContextManager } = require("@opentelemetry/context-zone"); | ||
const { B3Propagator } = require("@opentelemetry/propagator-b3"); | ||
const { registerInstrumentations } = require("@opentelemetry/instrumentation"); | ||
const { | ||
OTLPTraceExporter: OTLPTraceExporterProto, | ||
} = require("@opentelemetry/exporter-trace-otlp-proto/build/src/platform"); | ||
pichlermarc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const provider = new WebTracerProvider(); | ||
|
||
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests | ||
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the | ||
// exporter without delay | ||
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); | ||
provider.addSpanProcessor( | ||
new SimpleSpanProcessor(new OTLPTraceExporterProto()) | ||
); | ||
|
||
// provider.addSpanProcessor( | ||
pichlermarc marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commented out code can be removed, I think 🙂 |
||
// new SimpleSpanProcessor( | ||
// new OTLPTraceExporterProto({ | ||
// url: "https://api.honeycomb.io/v1/traces", | ||
// headers: { | ||
// }, | ||
// }) | ||
// ) | ||
// ); | ||
|
||
provider.register({ | ||
contextManager: new ZoneContextManager(), | ||
propagator: new B3Propagator(), | ||
}); | ||
|
||
registerInstrumentations({ | ||
instrumentations: [ | ||
new FetchInstrumentation({ | ||
ignoreUrls: [/localhost:8090\/sockjs-node/], | ||
propagateTraceHeaderCorsUrls: [ | ||
"https://cors-test.appspot.com/test", | ||
"https://httpbin.org/get", | ||
], | ||
clearTimingResources: true, | ||
}), | ||
], | ||
}); | ||
|
||
const webTracerWithZone = provider.getTracer("example-tracer-web"); | ||
|
||
const getData = (url) => | ||
fetch(url, { | ||
method: "GET", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
// example of keeping track of context between async operations | ||
const prepareClickEvent = () => { | ||
const url = "https://httpbin.org/get"; | ||
|
||
const element = document.getElementById("button1"); | ||
|
||
const onClick = () => { | ||
const singleSpan = webTracerWithZone.startSpan("files-series-info"); | ||
context.with(trace.setSpan(context.active(), singleSpan), () => { | ||
getData(url).then((_data) => { | ||
trace | ||
.getSpan(context.active()) | ||
.addEvent("fetching-single-span-completed"); | ||
singleSpan.end(); | ||
}); | ||
}); | ||
for (let i = 0, j = 5; i < j; i += 1) { | ||
const span = webTracerWithZone.startSpan(`files-series-info-${i}`); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
getData(url).then((_data) => { | ||
trace | ||
.getSpan(context.active()) | ||
.addEvent(`fetching-span-${i}-completed`); | ||
span.end(); | ||
}); | ||
}); | ||
} | ||
}; | ||
element.addEventListener("click", onClick); | ||
}; | ||
|
||
window.addEventListener("load", prepareClickEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,64 @@ | ||
const webpack = require('webpack'); | ||
const webpackMerge = require('webpack-merge'); | ||
const path = require('path'); | ||
const webpack = require("webpack"); | ||
const webpackMerge = require("webpack-merge"); | ||
const path = require("path"); | ||
|
||
const directory = path.resolve(__dirname); | ||
|
||
const common = { | ||
mode: 'development', | ||
mode: "development", | ||
entry: { | ||
metrics: 'examples/metrics/index.js', | ||
fetch: 'examples/fetch/index.js', | ||
'xml-http-request': 'examples/xml-http-request/index.js', | ||
fetchXhr: 'examples/fetchXhr/index.js', | ||
fetchXhrB3: 'examples/fetchXhrB3/index.js', | ||
zipkin: 'examples/zipkin/index.js', | ||
metrics: "examples/metrics/index.js", | ||
fetch: "examples/fetch/index.js", | ||
"xml-http-request": "examples/xml-http-request/index.js", | ||
fetchXhr: "examples/fetchXhr/index.js", | ||
fetchXhrB3: "examples/fetchXhrB3/index.js", | ||
fetchProtoExporter: "examples/fetchProtoExporter/index.js", | ||
zipkin: "examples/zipkin/index.js", | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].js', | ||
sourceMapFilename: '[file].map', | ||
path: path.resolve(__dirname, "dist"), | ||
filename: "[name].js", | ||
sourceMapFilename: "[file].map", | ||
}, | ||
target: 'web', | ||
target: "web", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js[x]?$/, | ||
exclude: /(node_modules)/, | ||
use: { | ||
loader: 'babel-loader', | ||
loader: "babel-loader", | ||
}, | ||
}, | ||
{ | ||
test: /\.ts$/, | ||
exclude: /(node_modules)/, | ||
use: { | ||
loader: 'ts-loader', | ||
loader: "ts-loader", | ||
}, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
modules: [ | ||
path.resolve(directory), | ||
'node_modules', | ||
], | ||
extensions: ['.ts', '.js', '.jsx', '.json'], | ||
modules: [path.resolve(directory), "node_modules"], | ||
extensions: [".ts", ".js", ".jsx", ".json"], | ||
}, | ||
optimization: { | ||
minimize: false, | ||
}, | ||
}; | ||
|
||
module.exports = webpackMerge.merge(common, { | ||
devtool: 'eval-source-map', | ||
devtool: "eval-source-map", | ||
devServer: { | ||
static: { | ||
directory: path.resolve(__dirname, 'examples'), | ||
directory: path.resolve(__dirname, "examples"), | ||
}, | ||
compress: true, | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify('development'), | ||
"process.env.NODE_ENV": JSON.stringify("development"), | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
experimental/packages/exporter-trace-otlp-proto/karma.conf.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*! | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const karmaWebpackConfig = require('../../../karma.webpack'); | ||
const karmaBaseConfig = require('../../../karma.base'); | ||
|
||
module.exports = (config) => { | ||
config.set(Object.assign({}, karmaBaseConfig, { | ||
webpack: karmaWebpackConfig, | ||
files: ['test/browser/index-webpack.ts'], | ||
preprocessors: { 'test/browser/index-webpack.ts': ['webpack'] } | ||
})) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this file has only formatting changes. If so, can you submit them in a separate PR and revert them here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also prefer single quotes over double quotes in the repo, but there is just no eslint rule for
*.js
files at the moment. For this reason, and for making this PR easier to review, undoning the formatting changes would be greatly appreciated 🙂