From 52824eb35375ce1514eaa4028fcde5b043708cce Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 26 Jun 2025 11:10:15 -0700 Subject: [PATCH] chore(examples): lint examples/memcached using shared top-level eslint config Refs: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2891 --- examples/memcached/.eslintrc.js | 26 ++++++++++++++++++++++++ examples/memcached/.npmrc | 1 + examples/memcached/index.js | 26 +++++++++++++++++++++--- examples/memcached/package.json | 2 ++ examples/memcached/tracer.js | 35 ++++++++++++++++++++++++--------- 5 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 examples/memcached/.eslintrc.js create mode 100644 examples/memcached/.npmrc diff --git a/examples/memcached/.eslintrc.js b/examples/memcached/.eslintrc.js new file mode 100644 index 0000000000..53452072e2 --- /dev/null +++ b/examples/memcached/.eslintrc.js @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const baseConfig = require('../../eslint.config'); + +module.exports = { + ...baseConfig, + env: { + node: true, + }, +}; diff --git a/examples/memcached/.npmrc b/examples/memcached/.npmrc new file mode 100644 index 0000000000..43c97e719a --- /dev/null +++ b/examples/memcached/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/examples/memcached/index.js b/examples/memcached/index.js index d25c2bc0db..f52096b7d1 100644 --- a/examples/memcached/index.js +++ b/examples/memcached/index.js @@ -1,3 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; require('./tracer')('example-resource'); @@ -9,12 +25,16 @@ const VALUE = `RAND:${Math.random().toFixed(4)}`; const LT = 10; const client = new Memcached(); -client.set(KEY, VALUE, LT, (err) => { +client.set(KEY, VALUE, LT, err => { assert.strictEqual(err, undefined); client.get(KEY, (err, result) => { assert.strictEqual(err, undefined); assert.strictEqual(result, VALUE); - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); - setTimeout(() => { console.log('Completed.'); }, 5000); + console.log( + 'Sleeping 5 seconds before shutdown to ensure all records are flushed.' + ); + setTimeout(() => { + console.log('Completed.'); + }, 5000); }); }); diff --git a/examples/memcached/package.json b/examples/memcached/package.json index fb48295596..2a1965a7f1 100644 --- a/examples/memcached/package.json +++ b/examples/memcached/package.json @@ -5,6 +5,8 @@ "description": "Example of Memcached client with OpenTelemetry", "main": "index.js", "scripts": { + "lint": "eslint . --ext=ts,js,mjs", + "lint:fix": "eslint . --ext=ts,js,mjs --fix", "docker:start": "docker run --rm -d --name otel-memcached -p 11211:11211 memcached:1.6.9-alpine", "docker:stop": "docker rm -f otel-memcached", "start": "node index.js" diff --git a/examples/memcached/tracer.js b/examples/memcached/tracer.js index cbb5f30392..0219411ce4 100644 --- a/examples/memcached/tracer.js +++ b/examples/memcached/tracer.js @@ -1,3 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; const opentelemetry = require('@opentelemetry/api'); @@ -7,27 +23,28 @@ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.VERBOSE); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); -const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base'); +const { + SimpleSpanProcessor, + ConsoleSpanExporter, +} = require('@opentelemetry/sdk-trace-base'); const { Resource } = require('@opentelemetry/resources'); const { ATTR_SERVICE_NAME } = require('@opentelemetry/semantic-conventions'); -const { MemcachedInstrumentation } = require('@opentelemetry/instrumentation-memcached'); +const { + MemcachedInstrumentation, +} = require('@opentelemetry/instrumentation-memcached'); -module.exports = (serviceName) => { +module.exports = serviceName => { const exporter = new ConsoleSpanExporter(); const provider = new NodeTracerProvider({ resource: new Resource({ [ATTR_SERVICE_NAME]: serviceName, }), - spanProcessors: [ - new SimpleSpanProcessor(exporter), - ], + spanProcessors: [new SimpleSpanProcessor(exporter)], }); registerInstrumentations({ tracerProvider: provider, - instrumentations: [ - new MemcachedInstrumentation(), - ], + instrumentations: [new MemcachedInstrumentation()], }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings