Skip to content
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

Cloud Run compatibility #1161

Closed
grayside opened this issue Nov 26, 2019 · 3 comments
Closed

Cloud Run compatibility #1161

grayside opened this issue Nov 26, 2019 · 3 comments
Assignees
Labels
api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@grayside
Copy link

grayside commented Nov 26, 2019

I've built a simple Hello World express service for Cloud Run, and can sometimes see data show up in the Trace console. However, most of the time it's not getting through.

This could easily be because CPU is withdrawn from the Cloud Run service as soon as a response is sent and there is no mechanism for cleanup operations when a container instance is halted.

Here's the most recent code I've tried:

// Initialize tracing agent.
const tracer = require('@google-cloud/trace-agent').start({
  samplingRate: 0,
  bufferSize: 1,
  flushDelaySeconds: 1,
});

// Bootstrap express app.
const sleep = require('util').promisify(setTimeout);
const express = require('express');
const app = express();

app.get('/', async (req, res) => {
  const span = tracer.createChildSpan({name: 'greeting'});
  const greeting = 'Howdy Friends';
  sleep(2000)
  span.endSpan();

  // Existing endSpan() call in express wrapper happens after response sent.
  // Adding this here to try forcing the data to publish.
  const root = tracer.getCurrentRootSpan();
  root.endSpan();

  await sleep(process.env.SLEEP_TIME || 0)
  res.status(200).send(greeting);
});

This code works fine from localhost but has only managed to submit telemetry in 2-3 requests from Cloud Run across many curl attempts in the last hour.

My expectation is that a guarantee of sending telemetry from Cloud Run will require something like the following:

const tracer = require('@google-cloud/trace-agent').start();

app.get('/', (req, res) => {
  const json = { fancy: 'value' };
  await tracer.FlushAndPublishNow();
  res.send(200).send(json);
});
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Nov 27, 2019
@bcoe bcoe added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Nov 27, 2019
@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Nov 27, 2019
@kjin kjin self-assigned this Dec 3, 2019
@kjin
Copy link
Contributor

kjin commented Dec 4, 2019

I ran your code exactly as written (adding only a statement to listen to a port) and could not seem to reproduce this -- I see 98/100 requests being traced (the remaining 2 might be due to your explanation above. This is after essentially following the Cloud Run tutorial (https://cloud.google.com/run/docs/quickstarts/build-and-deploy) and replacing the tutorial code with yours. Is your setup different?

For the record, I think you also need to await the sleep(2000) statement but that should be inconsequential here.

@grayside
Copy link
Author

grayside commented Dec 5, 2019

Alright, tried this again, and tonight it's working much more consistently. The question then: was the 90 minute period in which I tested this previously a fluke, or does this race condition vary between minor and severe impact?

I am essentially following the quickstart.

@kjin
Copy link
Contributor

kjin commented Dec 9, 2019

I'm not very familiar with the internal workings of Cloud Run, so unfortunately I can't answer that question.

Please re-open this bug if you observe traces not getting published again. Thanks!

@kjin kjin closed this as completed Dec 9, 2019
@google-cloud-label-sync google-cloud-label-sync bot added the api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants