Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/react-load/preact/.eslintrc.js
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
*
* https://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.
*/

'use strict';

const baseConfig = require('../../../eslint.config');

module.exports = {
...baseConfig,
env: {
browser: true,
},
};
1 change: 1 addition & 0 deletions examples/react-load/preact/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions examples/react-load/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"description": "Example of using @opentelemetry/plugin-react-load in browser with Preact",
"main": "index.js",
"scripts": {
"lint": "eslint . --ext=ts,js,mjs",
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
"build": "preact build --no-prerender",
"docker:start": "cd ./docker && docker-compose down && docker-compose up",
"docker:startd": "cd ./docker && docker-compose down && docker-compose up -d",
Expand Down Expand Up @@ -36,6 +38,7 @@
"sirv-cli": "1.0.3"
},
"dependencies": {
"@opentelemetry/api": "^1.0.0",
"@opentelemetry/context-zone": "^1.11.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.37.0",
"@opentelemetry/plugin-react-load": "^0.28.1",
Expand Down
73 changes: 43 additions & 30 deletions examples/react-load/preact/src/components/Content.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,72 @@
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load'
/*
* 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
*
* https://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.
*/

'use strict';

import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load';

class Content extends BaseOpenTelemetryComponent {
constructor(props){
super(props)
constructor(props) {
super(props);
this.state = {
results: null,
isLoading: false
}
isLoading: false,
};
}

componentDidMount(){
// eslint-disable-next-line class-methods-use-this
componentDidMount() {
// Example, do something here
}

buttonHandler() {
this.setState({isLoading: true})
const randomDelay = Math.random() * 10000;
this.setState({ isLoading: true });
const randomDelay = Math.random() * 10000;
setTimeout(() => {
this.setState({
isLoading: false,
results: randomDelay
})
},
randomDelay);
results: randomDelay,
});
}, randomDelay);
}

renderResults(){
if(this.state.isLoading){
renderResults() {
if (this.state.isLoading) {
return <div> Loading results...</div>;
}
if (!this.state.results){
return (
<div>No Results</div>
)
}
return (
<div>
Request was delayed {this.state.results} ms
</div>
)
if (!this.state.results) {
return <div>No Results</div>;
}
return <div>Request was delayed {this.state.results} ms</div>;
}

render() {
return (
<div>
<h1>React Plugin Demo App</h1>
<button onClick={() => this.buttonHandler()} style={{marginBottom: '20px'}}>
<button
onClick={() => this.buttonHandler()}
style={{ marginBottom: '20px' }}
>
Make Request
</button>
<div id="results">
{this.renderResults()}
</div>
<div id="results">{this.renderResults()}</div>
</div>
)
);
}
}

export default Content;
29 changes: 24 additions & 5 deletions examples/react-load/preact/src/components/Home.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
/*
* 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
*
* https://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.
*/

'use strict';

import { Link } from 'preact-router/match';
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load';

class Home extends BaseOpenTelemetryComponent {
// eslint-disable-next-line class-methods-use-this
render() {
return (
<div>
<h1>
React Plugin Demo App: Preact
</h1>
<Link href='/test'><button>Enter</button></Link>
<h1>React Plugin Demo App: Preact</h1>
<Link href="/test">
<button>Enter</button>
</Link>
</div>
)
);
}
}

Expand Down
55 changes: 36 additions & 19 deletions examples/react-load/preact/src/components/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import { h, Component} from 'preact';
/*
* 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
*
* https://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.
*/

'use strict';

import { Component } from 'preact';
import { Router } from 'preact-router';
import Home from './Home';
import Content from './Content';
Expand All @@ -7,23 +25,22 @@ import Tracer from '../web-tracer';
Tracer('react-load-preact-examples');

export default class App extends Component {

/** Gets fired when the route changes.
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
* @param {string} event.url The newly routed URL
*/
handleRoute = e => {
this.currentUrl = e.url;
};
/** Gets fired when the route changes.
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
* @param {string} event.url The newly routed URL
*/
handleRoute = e => {
this.currentUrl = e.url;
};

render() {
return (
<div id="app">
<Router onChange={this.handleRoute}>
<Home path="/" />
<Content path="/test"/>
</Router>
</div>
);
}
render() {
return (
<div id="app">
<Router onChange={this.handleRoute}>
<Home path="/" />
<Content path="/test" />
</Router>
</div>
);
}
}
18 changes: 18 additions & 0 deletions examples/react-load/preact/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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
*
* https://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.
*/

'use strict';

import App from './components/app';

export default App;
18 changes: 18 additions & 0 deletions examples/react-load/preact/src/sw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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
*
* https://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.
*/

'use strict';

import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw/';

setupRouting();
Expand Down
29 changes: 25 additions & 4 deletions examples/react-load/preact/src/web-tracer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
/*
* 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
*
* https://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.
*/

'use strict';

import {
ConsoleSpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

export default (serviceName) => {
export default serviceName => {
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
const exporter = new OTLPTraceExporter({
url: 'http://localhost:4318/v1/traces',
Expand All @@ -23,7 +44,7 @@ export default (serviceName) => {

const tracer = provider.getTracer(serviceName);

BaseOpenTelemetryComponent.setTracer(serviceName)
BaseOpenTelemetryComponent.setTracer(serviceName);

return tracer;
}
};
26 changes: 26 additions & 0 deletions examples/react-load/react/.eslintrc.js
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
*
* https://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.
*/

'use strict';

const baseConfig = require('../../../eslint.config');

module.exports = {
...baseConfig,
env: {
browser: true,
},
};
1 change: 1 addition & 0 deletions examples/react-load/react/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions examples/react-load/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"description": "Example of using @opentelemetry/plugin-react-load in browser with React",
"main": "index.jsx",
"scripts": {
"lint": "eslint . --ext=ts,js,mjs",
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
"build": "react-scripts build",
"dev": "react-scripts start",
"docker:start": "cd ./docker && docker-compose down && docker-compose up",
Expand Down Expand Up @@ -41,6 +43,7 @@
"@opentelemetry/core": "^0.25.0",
"@opentelemetry/exporter-collector": "^0.25.0",
"@opentelemetry/plugin-react-load": "^0.23.0",
"@opentelemetry/resources": "^0.25.0",
"@opentelemetry/sdk-trace-base": "^0.25.0",
"@opentelemetry/sdk-trace-web": "^0.25.0",
"@opentelemetry/semantic-conventions": "^1.27.0",
Expand Down
Loading