index.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>中电汇通 opentelemetry-js 示例</title>
  6. <base href="/">
  7. <!--
  8. https://www.w3.org/TR/trace-context/
  9. Set the `traceparent` in the server's HTML template code. It should be
  10. dynamically generated server side to have the server's request trace Id,
  11. a parent span Id that was set on the server's request span, and the trace
  12. flags to indicate the server's sampling decision
  13. (01 = sampled, 00 = not sampled).
  14. '{version}-{traceId}-{spanId}-{sampleDecision}'
  15. -->
  16. <meta name="traceparent" content="00-ab42124a3c573678d4d8b21ba52df3bf-d21f7bc17caa5aba-01" />
  17. <meta name="viewport" content="width=device-width, initial-scale=1">
  18. <!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> -->
  19. </head>
  20. <body>
  21. <h3>这是一个简单实例</h3>
  22. <br />
  23. <button id="button">Test</button>
  24. <script src="index.js" data-service-name="szhmh_front" data-service-version="1.0.0" data-app-alias="ZTGLPT"
  25. data-exporter-otlp-trace-endpoint="http://observe-front.cestong.com.cn/col/v1/traces" data-mode="dev"></script>
  26. <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  27. </body>
  28. <script>
  29. const getData = (url) => fetch(url, {
  30. method: 'GET',
  31. headers: {
  32. Accept: 'application/json',
  33. 'Content-Type': 'application/json',
  34. },
  35. });
  36. CecfOtel.OneTrace(() => {
  37. getData('https://httpbin.org/get?a=1').then((_data) => {
  38. console.log("a1", _data)
  39. })
  40. getData('https://httpbin.org/get?a=2').then((_data) => {
  41. console.log("a2", _data)
  42. })
  43. $.ajax({
  44. type: 'GET',
  45. url: 'https://httpbin.org/get?a=3',
  46. dataType: 'json',
  47. contentType: 'text/plain',
  48. async: true,
  49. success: function (res) {
  50. console.log("a3 ajax", res)
  51. }
  52. });
  53. });
  54. const button = document.querySelector("button");
  55. button.addEventListener("click", (event) => {
  56. button.textContent = `Click count: ${event.detail}`;
  57. });
  58. </script>
  59. </html>