### Install and Setup Logagent Source: https://sematext.com/docs/logagent Commands to install Logagent via npm and initialize it as a system service. ```bash # Make sure you have Node.js installed curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs # Install Logagent and run it as a system service sudo npm i -g @sematext/logagent sudo logagent-setup -i ``` -------------------------------- ### Install Gems Source: https://sematext.com/docs/tracing/sdks/ruby Run this command to install the specified gems. ```bash bundle install ``` -------------------------------- ### Install Logagent and ZeroMQ Plugin Source: https://sematext.com/docs/logagent/input-plugin-zeromq Global installation commands for the logagent core and the ZeroMQ input plugin. ```bash npm i -g @sematext/logagent npm i -g logagent-input-zeromq ``` -------------------------------- ### Install OpenTelemetry Composer packages Source: https://sematext.com/docs/tracing/sdks/php Install the SDK, OTLP exporter, and framework-specific auto-instrumentation packages. ```bash composer require \ open-telemetry/sdk \ open-telemetry/exporter-otlp \ open-telemetry/opentelemetry-auto-laravel ``` -------------------------------- ### Install Sematext Agent on Fedora Source: https://sematext.com/docs/agents/sematext-agent/linux-installation Use dnf to install the agent. ```bash sudo wget https://pub-repo.sematext.com/fedora/sematext.repo -O /etc/yum.repos.d/sematext.repo sudo dnf clean all sudo dnf install sematext-agent ``` -------------------------------- ### Install gRPC Exporter Source: https://sematext.com/docs/tracing/sdks/go Install the necessary Go package for OTLP gRPC tracing exports. ```bash go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc ``` -------------------------------- ### Install Logagent and Plugins on Windows Source: https://sematext.com/docs/logagent/installation-windows Commands to set up the npm environment and install the Logagent package along with required input plugins. ```batch md %ProgramData%\npm-cache md %ProgramData%\npm md %ProgramData%\npm\node_modules call npm config --global set prefix "%ProgramData%\npm" call npm config --global set cache "%ProgramData%\npm-cache" setx PATH "%PATH%;%ProgramData%\npm" /M call npm i -g @sematext/logagent call npm i -g logagent-input-elasticsearch-stats call npm i -g logagent-input-windows-events call npm i -g node-windows@1.0.0-beta.6 # run logagent windows version logagent-windows --help ``` -------------------------------- ### Install OpenTelemetry Dependencies Source: https://sematext.com/docs/tracing/sdks/go Commands to initialize a Go module and install the necessary OpenTelemetry SDK and OTLP HTTP exporter packages. ```bash go mod init your-service go get go.opentelemetry.io/otel go get go.opentelemetry.io/otel/sdk go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp ``` -------------------------------- ### Install Logagent and Plugin Source: https://sematext.com/docs/logagent/logagent-apple-location Global installation commands for the Logagent core and the Apple location plugin. ```bash npm i -g @sematext/logagent npm i -g logagent-apple-location ``` -------------------------------- ### Install Sematext Agent on Debian/Ubuntu Source: https://sematext.com/docs/agents/sematext-agent/linux-installation Configure the apt source and install the agent package. ```bash echo "deb http://pub-repo.sematext.com/debian sematext main" | sudo tee /etc/apt/sources.list.d/sematext.list > /dev/null wget -O - https://pub-repo.sematext.com/debian/sematext.gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install sematext-agent ``` ```bash echo "deb http://pub-repo.sematext.com/ubuntu sematext main" | sudo tee /etc/apt/sources.list.d/sematext.list > /dev/null wget -O - https://pub-repo.sematext.com/ubuntu/sematext.gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install sematext-agent ``` -------------------------------- ### Logagent Configuration Examples Source: https://sematext.com/docs/logagent/installation-windows Example configurations for sending Windows events to local Elasticsearch or Sematext Logs. ```yaml options: includeOriginalLine: false suppress: true input: windowsEvent: module: logagent-input-windows-events # query events every 10 seconds interval: 10 maxEvents: 1000 # if you're tailing files, you need to escape backslashes files: - 'c:\\tmp\\testfile.log' output: local-es: module: elasticsearch url: http://localhost:9200 index: windows_events ``` ```yaml output: sematext: module: elasticsearch url: https://logsene-receiver.sematext.com # for the EU datacenter, it's https://logsene-receiver.eu.sematext.com index: LOGSENE-APP-TOKEN-GOES-HERE ``` -------------------------------- ### Install OpenTelemetry Packages Source: https://sematext.com/docs/tracing/sdks/python Install the necessary OpenTelemetry SDK and OTLP exporter packages via pip. ```bash pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp ``` -------------------------------- ### Logagent Processing Chain Example Source: https://sematext.com/docs/logagent/filters A conceptual example showing the flow from input plugins through filters and parsers to output plugins. ```text 1. Input: Tail Web Server Log -g '/var/log/httpd/access.log' 2. Input Filter: Grep URLs of interest 'login|register|upgrade' 3. Parser: Parse Log and generate fields like URL, status code, size, referrer, country etc. 4. Output Filter: Drop irelevant log events like redirects (status=302) 5. Output Plugin: Store filtered log-events in Elasticsearch/OpenSearch ``` -------------------------------- ### Install Logagent and Nova SDS Plugin Source: https://sematext.com/docs/logagent/logagent-novasds Global installation commands for the logagent core and the specific Nova SDS plugin. ```bash npm i -g @sematext/logagent npm i -g logagent-novasds ``` -------------------------------- ### Install Logagent and ZeroMQ Plugin Source: https://sematext.com/docs/logagent/output-plugin-zeromq Use npm to install the global logagent package and the specific ZeroMQ output plugin. ```bash npm i -g @sematext/logagent npm i -g logagent-output-zeromq ``` -------------------------------- ### Go Zipkin Setup Source: https://sematext.com/docs/tracing/migration/zipkin Initialization of a Zipkin reporter and tracer in Go. ```go import ( "github.com/openzipkin/zipkin-go" zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" ) reporter := zipkinhttp.NewReporter("http://zipkin:9411/api/v2/spans") tracer, err := zipkin.NewTracer( reporter, zipkin.WithLocalEndpoint(&zipkin.Endpoint{ ServiceName: "my-service", }), ) ``` -------------------------------- ### Go OpenTelemetry Setup Source: https://sematext.com/docs/tracing/migration/zipkin Initialization of an OTLP exporter and tracer provider in Go. ```go import ( "context" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/semconv/v1.17.0/httpconv" ) ctx := context.Background() // Create OTLP exporter exporter, err := otlptracehttp.New(ctx, otlptracehttp.WithEndpoint("http://localhost:4338"), ) // Create tracer provider tp := trace.NewTracerProvider( trace.WithBatcher(exporter), trace.WithResource(resource.NewWithAttributes( semconv.ServiceNameKey.String("my-service"), )), trace.WithSampler(trace.TraceIDRatioBased(0.1)), ) otel.SetTracerProvider(tp) tracer := tp.Tracer("my-service") ``` -------------------------------- ### Install Node.js on Debian/Ubuntu Source: https://sematext.com/docs/logagent/installation Use the NodeSource setup script to install Node.js 12.x on Debian or Ubuntu systems. ```bash curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs ``` -------------------------------- ### Install GnuPG Source: https://sematext.com/docs/monitoring/spm-faq Install the gnupg package required for Debian-based agent installations. ```bash sudo apt install gnupg ``` -------------------------------- ### Subscribe to MQTT Topics Source: https://sematext.com/docs/logagent/output-plugin-mqtt Installs the MQTT client and subscribes to a topic to verify incoming log events. ```bash npm i -g mqtt mqtt subscribe -h test.mosquitto.org -t sensor-data ``` -------------------------------- ### Apply and Enable Service Source: https://sematext.com/docs/logagent/how-to-centralize-linux-system-journal Reload systemd configuration and enable the upload service to start on boot. ```bash systemctl daemon-reload sudo systemctl enable systemd-journal-upload.service ``` -------------------------------- ### Install Redis Instrumentation Source: https://sematext.com/docs/tracing/sdks/nodejs Install the required package for Redis tracing. ```bash npm install @opentelemetry/instrumentation-redis ``` -------------------------------- ### Configure Service Name Matching Source: https://sematext.com/docs/tracing/troubleshooting Examples showing how to define the service name in the application and register it in the agent. ```javascript // Your app sets: const resource = new Resource({ 'service.name': 'frontend' }); ``` ```bash sudo /opt/spm/spm-monitor/bin/st-agent otel services add \ --service-names "frontend" \ --token-group "your-group" ``` -------------------------------- ### Install PostgreSQL Instrumentation Source: https://sematext.com/docs/tracing/sdks/nodejs Install the required package for PostgreSQL tracing. ```bash npm install @opentelemetry/instrumentation-pg ``` -------------------------------- ### Install MongoDB Instrumentation Source: https://sematext.com/docs/tracing/sdks/nodejs Install the required package for MongoDB tracing. ```bash npm install @opentelemetry/instrumentation-mongodb ``` -------------------------------- ### Install CocoaPods dependencies Source: https://sematext.com/docs/tracing/sdks/ios-swift Run the install command after updating your Podfile. ```bash pod install ``` -------------------------------- ### Start Logagent Source: https://sematext.com/docs/logagent/input-github-webhook Command to launch the Logagent server using the specified configuration file. ```bash logagent --config github.yml ``` -------------------------------- ### Install graygelf module Source: https://sematext.com/docs/logagent/input-plugin-gelf Install the required graygelf module globally. ```bash npm i -g graygelf # sudo npm i -g --unsafe-perm graygelf ``` -------------------------------- ### Execute Deployment Source: https://sematext.com/docs/integration/terraform Apply the updated configuration to the infrastructure. ```bash $ terraform execute ``` -------------------------------- ### Install systemd-journal-remote Source: https://sematext.com/docs/logagent/how-to-centralize-linux-system-journal Install the necessary package to enable journal uploading. ```bash sudo apt-get install systemd-journal-remote ``` -------------------------------- ### Node.js Zipkin Setup Source: https://sematext.com/docs/tracing/migration/zipkin Standard initialization of a Zipkin tracer in Node.js. ```javascript const zipkin = require('zipkin'); const {BatchRecorder} = require('zipkin'); const {HttpLogger} = require('zipkin-transport-http'); const recorder = new BatchRecorder({ logger: new HttpLogger({ endpoint: 'http://zipkin:9411/api/v2/spans' }) }); const tracer = new zipkin.Tracer({ ctxImpl: new zipkin.ExplicitContext(), recorder, localServiceName: 'my-service' }); ``` -------------------------------- ### Install Node.js Dependencies Source: https://sematext.com/docs/tracing/troubleshooting Install the auto-instrumentation and OTLP HTTP exporter packages. ```bash # Reinstall dependencies npm install @opentelemetry/auto-instrumentations-node npm install @opentelemetry/exporter-trace-otlp-http ``` -------------------------------- ### Configure Kafka Broker Monitoring Source: https://sematext.com/docs/integration/kafka Run the setup script to configure the agent for a Kafka broker, then update the JMX options in the startup script. ```bash sudo bash /opt/spm/bin/setup-sematext \ --monitoring-token \ --app-type kafka \ --app-subtype kafka-broker \ --agent-type javaagent \ --infra-token ``` ```bash -Dcom.sun.management.jmxremote -javaagent:/opt/spm/spm-monitor/lib/spm-monitor-generic.jar=:kafka-broker:default ``` -------------------------------- ### Install OpenTelemetry dependencies Source: https://sematext.com/docs/tracing/getting-started Installs the necessary OpenTelemetry distribution and auto-instrumentation packages. ```bash pip install opentelemetry-distro[otlp] opentelemetry-bootstrap -a install ``` -------------------------------- ### Initialize OpenTelemetry SDK Source: https://sematext.com/docs/tracing/sdks/nodejs Configure and start the NodeSDK with resource attributes and an OTLP trace exporter. ```javascript const { NodeSDK } = require('@opentelemetry/sdk-node'); const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); const { Resource } = require('@opentelemetry/resources'); const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions'); const sdk = new NodeSDK({ resource: new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: 'your-service-name', [SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0', [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: 'production', }), traceExporter: new OTLPTraceExporter({ url: 'http://localhost:4338', }), }); sdk.start(); // Get tracer for manual instrumentation const { trace } = require('@opentelemetry/api'); const tracer = trace.getTracer('your-service-name'); module.exports = { tracer }; ``` -------------------------------- ### Initialize OpenTelemetry Configuration Source: https://sematext.com/docs/tracing/sdks/ios-swift Create a singleton class to manage the TracerProvider, configure resource attributes, and set up the OTLP HTTP exporter. ```swift import Foundation import OpenTelemetryApi import OpenTelemetrySdk import OpenTelemetryProtocolExporterHTTP class TracingConfiguration { static let shared = TracingConfiguration() private(set) var tracer: Tracer! private var tracerProvider: TracerProvider! private init() { setupOpenTelemetry() } private func setupOpenTelemetry() { // Configure resource with service information let resource = Resource(attributes: [ ResourceAttributes.serviceName.rawValue: .string("my-ios-app"), ResourceAttributes.serviceVersion.rawValue: .string(getAppVersion()), "environment": .string(isDebugBuild() ? "development" : "production"), "platform": .string("iOS"), "os.version": .string(UIDevice.current.systemVersion) ]) // Ship traces directly to the Sematext managed OTLP receiver over HTTPS. // US endpoint shown; for EU use https://otlp-receiver.eu.sematext.com/v1/traces let otlpConfiguration = OtlpConfiguration( endpoint: URL(string: "https://otlp-receiver.sematext.com/v1/traces")!, headers: ["Authorization": "Bearer your-api-key"] // Add authentication ) let otlpTraceExporter = OtlpHttpTraceExporter( configuration: otlpConfiguration ) // Configure span processor with batching let spanProcessor = BatchSpanProcessor( spanExporter: otlpTraceExporter, scheduleDelay: 5, // Send every 5 seconds maxQueueSize: 2048, maxExportBatchSize: 512 ) // Build tracer provider tracerProvider = TracerProviderBuilder() .add(spanProcessor: spanProcessor) .with(resource: resource) .build() // Register as global tracer provider OpenTelemetry.registerTracerProvider(tracerProvider: tracerProvider) // Get tracer for application use tracer = tracerProvider.get( instrumentationName: "my-ios-app", instrumentationVersion: getAppVersion() ) } private func getAppVersion() -> String { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0" } private func isDebugBuild() -> Bool { #if DEBUG return true #else return false #endif } } ``` -------------------------------- ### Install Node.js Monitor Plugin Source: https://sematext.com/docs/logagent/monitoring Install the required plugin for non-containerized environments. ```bash npm i -g @sematext/logagent-nodejs-monitor ``` -------------------------------- ### Logagent output example Source: https://sematext.com/docs/logagent/output-filter-removefields Example output showing masked fields after processing. ```text logSource: httpd _type: access_common remote_id: - method: GET path: /user/ANONYMIZED-DATA message: GET /user/ANONYMIZED-DATA http_version: HTTP/1.1 status_code: 304 size: 0 @timestamp: Thu Apr 26 2018 22:02:26 GMT+0200 (CEST) ``` -------------------------------- ### Instrument Gin Application Source: https://sematext.com/docs/tracing/sdks/go Example showing how to register the otelgin middleware and manually create spans within handlers. ```go package main import ( "context" "net/http" "github.com/gin-gonic/gin" "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" ) func main() { shutdown := initTracer() defer shutdown(context.Background()) r := gin.Default() // Add OpenTelemetry middleware r.Use(otelgin.Middleware("your-service-name")) r.GET("/users/:id", getUserHandler) r.Run(":8080") } func getUserHandler(c *gin.Context) { ctx := c.Request.Context() tracer := otel.Tracer("user-service") ctx, span := tracer.Start(ctx, "get-user-handler") defer span.End() userID := c.Param("id") span.SetAttributes( attribute.String("user.id", userID), attribute.String("http.method", c.Request.Method), attribute.String("http.route", c.FullPath()), ) // Your business logic user, err := fetchUser(ctx, userID) if err != nil { span.RecordError(err) span.SetStatus(codes.Error, err.Error()) c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal server error"}) return } span.SetAttributes(attribute.String("user.name", user.Name)) c.JSON(http.StatusOK, gin.H{"user": user}) } type User struct { ID string `json:"id"` Name string `json:"name"` } func fetchUser(ctx context.Context, userID string) (*User, error) { tracer := otel.Tracer("user-service") ctx, span := tracer.Start(ctx, "fetch-user-db") defer span.End() span.SetAttributes( attribute.String("user.id", userID), attribute.String("database.operation", "SELECT"), ) // Simulate database operation user := &User{ ID: userID, Name: "John Doe", } return user, nil } ``` -------------------------------- ### Auto-Discover and Install Instrumentations Source: https://sematext.com/docs/tracing/sdks/python Automatically detect and install instrumentation libraries for packages in the environment. ```bash opentelemetry-bootstrap -a install ``` -------------------------------- ### Install Logagent npm package Source: https://sematext.com/docs/logagent/installation-mac Installs the Logagent package globally using npm. ```bash sudo npm i -g @sematext/logagent ``` -------------------------------- ### Configure Kafka Consumer Monitoring Source: https://sematext.com/docs/integration/kafka Setup the agent for Kafka consumers and apply the required JVM startup properties. ```bash sudo bash /opt/spm/bin/setup-sematext \ --monitoring-token \ --app-type kafka \ --app-subtype kafka-consumer \ --agent-type javaagent \ --infra-token ``` ```bash -Dcom.sun.management.jmxremote -javaagent:/opt/spm/spm-monitor/lib/spm-monitor-generic.jar=:kafka-consumer:default ``` -------------------------------- ### Debug Mode Output Example Source: https://sematext.com/docs/logagent/faq Example of the output generated when debug mode is enabled. ```text Pattern match: log #4 /^([\w|\s]+\s\d{2}\s[\d|\:|\.]+)\s+(<.+?>)\s(.*)/ ["ts","service","message"] Pattern match: system_log #3 /^([\w|\s]+\s+\d{1,2}\s[\d|\:|\.]+)\s+(\S+)\s+(.*)\:\s(.*)/ ["ts","host","service","message"] Pattern match: system_log #3 /^([\w|\s]+\s+\d{1,2}\s[\d|\:|\.]+)\s+(\S+)\s+(.*)\:\s(.*)/ ["ts","host","service","message"] {"logSource":"/var/log/wifi.log","_type":"log","service":"","message":"IO80211Interface::updateReport _peerManager is missing","@timestamp":"2017-09-30T10:24:39.063Z"} ``` -------------------------------- ### Initialize gRPC Tracer Source: https://sematext.com/docs/tracing/sdks/go Establish a gRPC connection and initialize the OTLP exporter for tracing. ```go import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) func initTracerGRPC() func(context.Context) error { ctx := context.Background() conn, err := grpc.DialContext(ctx, "localhost:4337", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), ) if err != nil { log.Fatalf("Failed to create gRPC connection: %v", err) } exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithGRPCConn(conn), ) if err != nil { log.Fatalf("Failed to create exporter: %v", err) } // Rest of the setup... return tracerProvider.Shutdown } ``` -------------------------------- ### Install Sematext Agent via Windows CMD Source: https://sematext.com/docs/agents/sematext-agent/windows-installation Use the Windows Command Prompt to install the agent. Run these commands as Administrator. ```batch start /wait msiexec /qn /i "AGENT_MSI_INSTALLER" /L*V "AGENT_MSI_INSTALLER.log" INFRA_TOKEN=YOUR_INFRA_APP_TOKEN REGION=YOUR_REGION_EU_or_US ``` ```batch start /wait msiexec /qn /i "AGENT_MSI_INSTALLER" /L*V "AGENT_MSI_INSTALLER.log" INFRA_TOKEN=YOUR_INFRA_APP_TOKEN REGION=YOUR_REGION_EU_or_US LOGS_TOKEN=YOUR_LOGS_APP_TOKEN ``` ```batch start /wait msiexec /qn /i "sematext-agent-latest.msi" /L*V "sematext-agent-latest.msi.log" INFRA_APP_TOKEN=7511db7f-c060-4e10-b667-5f2653d4933e REGION=EU LOGS_TOKEN=7611db7f-c060-4e10-b667-5f2653d4966b ``` -------------------------------- ### Install Required Dependencies Source: https://sematext.com/docs/tracing/sdks/nodejs Install the necessary OpenTelemetry packages for Node.js instrumentation and OTLP exporting. ```bash # Make sure all dependencies are installed npm install @opentelemetry/auto-instrumentations-node @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-http ``` -------------------------------- ### Configure PostgreSQL Instrumentation Source: https://sematext.com/docs/tracing/sdks/nodejs Initialize the SDK with PostgreSQL instrumentation. ```javascript const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg'); const sdk = new NodeSDK({ instrumentations: [ getNodeAutoInstrumentations(), new PgInstrumentation() ], // ... other configuration }); ``` -------------------------------- ### Install TypeScript Dependencies Source: https://sematext.com/docs/tracing/sdks/nodejs Commands to install the required TypeScript development dependencies and OpenTelemetry packages. ```bash npm install --save-dev typescript @types/node npm install @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node ``` -------------------------------- ### PostgreSQL Configuration Parameters Source: https://sematext.com/docs/guide/remote-dbs-guide Use these flags when running the setup script to connect to a remote PostgreSQL instance. ```bash --ST_MONITOR_POSTGRESQL_HOST_PORT 'remote-host:5432' --ST_MONITOR_POSTGRESQL_DB_USER 'your-username' --ST_MONITOR_POSTGRESQL_DB_PASSWORD 'your-password' --ST_MONITOR_POSTGRESQL_DB_NAME 'your-database' ``` -------------------------------- ### Start Logagent Source: https://sematext.com/docs/logagent/input-plugin-azure-eventhub Execute Logagent using the specified configuration file to begin streaming events. ```bash logagent --config azure-events.yml --yaml ``` -------------------------------- ### Install Framework-Specific Instrumentation Source: https://sematext.com/docs/tracing/sdks/python Install individual instrumentation packages for specific Python frameworks and libraries. ```bash pip install opentelemetry-instrumentation-flask ``` ```bash pip install opentelemetry-instrumentation-django ``` ```bash pip install opentelemetry-instrumentation-fastapi ``` ```bash pip install opentelemetry-instrumentation-requests ``` ```bash pip install opentelemetry-instrumentation-sqlalchemy ``` ```bash pip install opentelemetry-instrumentation-redis ``` -------------------------------- ### Send MQTT Messages Source: https://sematext.com/docs/logagent/input-plugin-mqtt-broker Install the MQTT client and publish test messages to the broker. ```bash npm i -g mqtt mqtt pub -h localhost -p 1833 -t log-messages -m "Hello MQTT" mqtt pub -h localhost -p 1833 -t sensor-data -m '{"temperature": 11}' ``` -------------------------------- ### Create Tracing Configuration Source: https://sematext.com/docs/tracing/sdks/nodejs Initialize the NodeSDK with the OTLP exporter and auto-instrumentations in a dedicated file. ```javascript const { NodeSDK } = require('@opentelemetry/sdk-node'); const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node'); const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); const sdk = new NodeSDK({ serviceName: 'your-service-name', traceExporter: new OTLPTraceExporter({ url: 'http://localhost:4338', }), instrumentations: [getNodeAutoInstrumentations()], }); sdk.start(); ``` -------------------------------- ### Install OpenTelemetry PHP extension Source: https://sematext.com/docs/tracing/sdks/php Use PECL to install the OpenTelemetry extension required for auto-instrumentation. ```bash pecl install opentelemetry ``` -------------------------------- ### Install CA Certificates Source: https://sematext.com/docs/monitoring/spm-faq Install the ca-certificates package to resolve SSL certificate trust issues. ```bash sudo apt-get install ca-certificates sudo yum install ca-certificates ``` -------------------------------- ### Instrument SQL Database with OpenTelemetry Source: https://sematext.com/docs/tracing/sdks/go Example showing how to register a wrapped SQL driver and perform traced database queries. ```go package main import ( "context" "database/sql" "go.opentelemetry.io/contrib/instrumentation/database/sql/otelsql" _ "github.com/lib/pq" ) func initDB() (*sql.DB, error) { // Register the wrapped driver driverName, err := otelsql.Register("postgres", otelsql.WithAttributes( semconv.DBSystemPostgreSQL, ), ) if err != nil { return nil, err } // Open database with the wrapped driver db, err := sql.Open(driverName, "postgresql://user:password@localhost/dbname?sslmode=disable") if err != nil { return nil, err } return db, nil } func fetchUserFromDB(ctx context.Context, db *sql.DB, userID string) (*User, error) { tracer := otel.Tracer("user-service") ctx, span := tracer.Start(ctx, "fetch-user-query") defer span.End() span.SetAttributes( attribute.String("user.id", userID), attribute.String("db.operation", "SELECT"), attribute.String("db.table", "users"), ) var user User err := db.QueryRowContext(ctx, "SELECT id, name FROM users WHERE id = $1", userID). Scan(&user.ID, &user.Name) if err != nil { span.RecordError(err) return nil, err } return &user, nil } ```