Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Attaching user interaction spans and initial load span #250

Open
rikonor opened this issue Mar 18, 2020 · 1 comment
Open

Attaching user interaction spans and initial load span #250

rikonor opened this issue Mar 18, 2020 · 1 comment

Comments

@rikonor
Copy link

rikonor commented Mar 18, 2020

Is your feature request related to a problem? Please describe.
I'm encountering a use-case where it'd be handy if I could view both initial load data as well as custom spans together. Right now, any custom spans appear separately from the initial load data.

Describe the solution you'd like
I'd like to have some global span that gets started automatically via the initial load, but then requires manual closing. The initial page load span can live under that global span, and any user interaction or custom spans will live under that global span as well.

Describe alternatives you've considered
I've been digging through the code to see if it should already be possible to do this, but it was not able to find a solution.

@rikonor rikonor changed the title Nesting user interaction spans under initial load span Attaching user interaction spans and initial load span Mar 18, 2020
@rikonor
Copy link
Author

rikonor commented Mar 18, 2020

May have figured a way to make this happen:

import { tracing } from "@opencensus/web-core";
import { OCAgentExporter } from "@opencensus/web-exporter-ocagent";
import {
  getPerfEntries,
  getInitialLoadRootSpan
} from "@opencensus/web-instrumentation-perf";

const TRACE_ENDPOINT = "/v1/trace";

tracing.registerExporter(
  new OCAgentExporter({
    agentEndpoint: `${window.ocAgent}${TRACE_ENDPOINT}`,
    serviceName: window.ocServiceName
  })
);

let rootSpan = getInitialLoadRootSpan(tracing.tracer, getPerfEntries());

setTimeout(() => {
  rootSpan.end();
}, 5000);

setTimeout(() => {
  let childSpan = tracing.tracer.startChildSpan({
    name: "child-1",
    childOf: rootSpan
  });

  setTimeout(() => {
    childSpan.end();
  }, 500);
}, 1000);

Seems to allow exporting initial page load as well as custom events under the same root.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant