OpenCensus and AppEngine Flex

Dino Oliva
Jan 11 · 3 min read

try (
// create a new scoped span for calling client libraries
Scope traceScope = OpenCensusTraceUtil
.createSpanBuilder("Work:Get").startScopedSpan()) {
Storage storage = StorageOptions. ...
BlobId blobId = BlobId.of(BUCKET_NAME, BLOB_NAME);
// Upload a blob.
BlobInfo blobInfo = BlobInfo.newBuilder(blobId)...;
Blob blob =
storage.create(blobInfo, CONTENT_STRING.getBytes(UTF_8));
// Read a blob.
byte[] content = storage.readAllBytes(blobId);
String contentString = new String(content, UTF_8);
if (!contentString.equals(CONTENT_STRING)) {
throw new RuntimeException("Invalid read after upload.");
// Delete a blob.

Enabling OpenCensus

// Initialization
static {
if (!PROJECT_ID.isEmpty()) {
try {
// Initialize trace exporter.
} catch (IOException exn) {
if (exn == null) {
System.err.println("Null exn");

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade