-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init commit for migration * update * fix some build * file name * address comments * Rename BasicTracerNode.ts to basicTracerNode.ts * Rename GRPCServer.ts to grpcServer.ts * Rename HttpServer.ts to httpServer.ts * clear up samples * updates * delete unused file * yaml file * update package version * udpate build
- Loading branch information
Showing
56 changed files
with
1,675 additions
and
2,351 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
APPLICATIONINSIGHTS_CONNECTION_STRING=<your connection string> |
83 changes: 83 additions & 0 deletions
83
sdk/monitor/monitor-opentelemetry-exporter/samples-dev/basicTracerNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* This example shows how to use | ||
* [@opentelemetry/tracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing) | ||
* to instrument a simple Node.js application - e.g. a batch job. | ||
* | ||
* @summary use opentelemetry tracing to instrument a Node.js application. Basic use of Tracing in Node.js application. | ||
*/ | ||
|
||
import * as opentelemetry from "@opentelemetry/api"; | ||
import { Resource } from "@opentelemetry/resources"; | ||
import { ResourceAttributes } from "@opentelemetry/semantic-conventions"; | ||
import { BasicTracerProvider, SimpleSpanProcessor } from "@opentelemetry/tracing"; | ||
import { AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const provider = new BasicTracerProvider({ | ||
resource: new Resource({ | ||
[ResourceAttributes.SERVICE_NAME]: "basic-service" | ||
}) | ||
}); | ||
|
||
// Configure span processor to send spans to the exporter | ||
const exporter = new AzureMonitorTraceExporter({ | ||
connectionString: | ||
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>" | ||
}); | ||
provider.addSpanProcessor(new SimpleSpanProcessor(exporter as any)); | ||
|
||
/** | ||
* Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings. | ||
* | ||
* This registers the tracer provider with the OpenTelemetry API as the global | ||
* tracer provider. This means when you call API methods like | ||
* `opentelemetry.trace.getTracer`, they will use this tracer provider. If you | ||
* do not register a global tracer provider, instrumentation which calls these | ||
* methods will receive no-op implementations. | ||
*/ | ||
provider.register(); | ||
const tracer = opentelemetry.trace.getTracer("example-basic-tracer-node"); | ||
|
||
export async function main() { | ||
// Create a span. A span must be closed. | ||
const parentSpan = tracer.startSpan("main"); | ||
for (let i = 0; i < 10; i += 1) { | ||
doWork(parentSpan); | ||
} | ||
// Be sure to end the span. | ||
parentSpan.end(); | ||
|
||
// flush and close the connection. | ||
exporter.shutdown(); | ||
} | ||
|
||
function doWork(parent: opentelemetry.Span) { | ||
// Start another span. In this example, the main method already started a | ||
// span, so that'll be the parent span, and this will be a child span. | ||
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), parent); | ||
const span = tracer.startSpan("doWork", undefined, ctx); | ||
|
||
// simulate some random work. | ||
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) { | ||
// empty | ||
} | ||
|
||
// Set attributes to the span. | ||
span.setAttribute("key", "value"); | ||
|
||
// Annotate our span to capture metadata about our operation | ||
span.addEvent("invoking doWork"); | ||
|
||
span.end(); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error("An error occurred:", error); | ||
process.exit(1); | ||
}); |
129 changes: 129 additions & 0 deletions
129
sdk/monitor/monitor-opentelemetry-exporter/samples-dev/httpSample.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* OpenTelemetry HTTP Instrumentation allows the user to | ||
* automatically collect trace data and export them to | ||
* the backend of choice (we can use Zipkin or Jaeger for this example), | ||
* to give observability to distributed systems. | ||
* | ||
* This is a simple example that demonstrates tracing HTTP request from client to server. | ||
* The example shows key aspects of tracing such as | ||
* - Root Span (on Client) | ||
* - Child Span (on Client) | ||
* - Child Span from a Remote Parent (on Server) | ||
* - SpanContext Propagation (from Client to Server) | ||
* - Span Events | ||
* - Span Attributes | ||
* | ||
* @summary demonstrates OpenTelemetry http Instrumentation. It is about how OpenTelemetry will instrument the Node.js native http module. | ||
*/ | ||
import api from "@opentelemetry/api"; | ||
import { registerInstrumentations } from "@opentelemetry/instrumentation"; | ||
import { NodeTracerProvider } from "@opentelemetry/node"; | ||
import { SimpleSpanProcessor, Tracer } from "@opentelemetry/tracing"; | ||
import { AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter"; | ||
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
/********************************************************************* | ||
* OPEN TELEMETRY SETUP | ||
**********************************************************************/ | ||
let serverTracer: Tracer; | ||
let clientTracer: Tracer; | ||
setupOpenTelemetry(); | ||
|
||
// Open Telemetry setup need to happen before http library is loaded | ||
import http from "http"; | ||
|
||
/********************************************************************* | ||
* HTTP SERVER SETUP | ||
**********************************************************************/ | ||
/** Starts a HTTP server that receives requests on sample server port. */ | ||
function startServer(port: number) { | ||
// Creates a server | ||
const server = http.createServer(handleRequest); | ||
// Starts the server | ||
server.listen(port, () => { | ||
console.log(`Node HTTP listening on ${port}`); | ||
}); | ||
} | ||
|
||
/** A function which handles requests and send response. */ | ||
function handleRequest(request: any, response: any) { | ||
const currentSpan = api.trace.getSpan(api.context.active()); | ||
if (currentSpan) { | ||
// display traceid in the terminal | ||
console.log(`traceid: ${currentSpan.spanContext().traceId}`); | ||
} | ||
const span = serverTracer.startSpan("handleRequest", { | ||
kind: 1, // server | ||
attributes: { key: "value" } | ||
}); | ||
// Annotate our span to capture metadata about the operation | ||
span.addEvent("invoking handleRequest"); | ||
|
||
const body = []; | ||
request.on("error", (err: Error) => console.log(err)); | ||
request.on("data", (chunk: string) => body.push(chunk)); | ||
request.on("end", () => { | ||
// deliberately sleeping to mock some action. | ||
setTimeout(() => { | ||
span.end(); | ||
response.end("Hello World!"); | ||
}, 2000); | ||
}); | ||
} | ||
|
||
startServer(8080); | ||
|
||
/********************************************************************* | ||
* HTTP CLIENT SETUP | ||
**********************************************************************/ | ||
/** A function which makes requests and handles response. */ | ||
function makeRequest() { | ||
// span corresponds to outgoing requests. Here, we have manually created | ||
// the span, which is created to track work that happens outside of the | ||
// request lifecycle entirely. | ||
const span = clientTracer.startSpan("makeRequest"); | ||
api.context.with(api.trace.setSpan(api.context.active(), span), () => { | ||
http.get( | ||
{ | ||
host: "localhost", | ||
port: 8080 | ||
}, | ||
(response) => { | ||
const body: any = []; | ||
response.on("data", (chunk) => body.push(chunk)); | ||
response.on("end", () => { | ||
console.log(body.toString()); | ||
span.end(); | ||
}); | ||
} | ||
); | ||
}); | ||
} | ||
makeRequest(); | ||
|
||
function setupOpenTelemetry() { | ||
const provider = new NodeTracerProvider(); | ||
const exporter = new AzureMonitorTraceExporter({ | ||
connectionString: | ||
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>" | ||
}); | ||
|
||
provider.addSpanProcessor(new SimpleSpanProcessor(exporter as any)); | ||
|
||
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings | ||
provider.register(); | ||
|
||
registerInstrumentations({ | ||
// // when boostraping with lerna for testing purposes | ||
instrumentations: [new HttpInstrumentation()] | ||
}); | ||
serverTracer = provider.getTracer("serverTracer"); | ||
clientTracer = provider.getTracer("clientTracer"); | ||
} |
67 changes: 0 additions & 67 deletions
67
sdk/monitor/monitor-opentelemetry-exporter/samples/@azure/storage-blob/README.md
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-242 KB
...r/monitor-opentelemetry-exporter/samples/@azure/storage-blob/images/storage.png
Binary file not shown.
49 changes: 0 additions & 49 deletions
49
...monitor-opentelemetry-exporter/samples/@azure/storage-blob/javascript/README.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.