<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cagri Yonca on Medium]]></title>
        <description><![CDATA[Stories by Cagri Yonca on Medium]]></description>
        <link>https://medium.com/@cagriyonca?source=rss-d879af208b34------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5fi6DbUB94UM05GV9zb3yw.jpeg</url>
            <title>Stories by Cagri Yonca on Medium</title>
            <link>https://medium.com/@cagriyonca?source=rss-d879af208b34------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:13:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cagriyonca/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Monitoring compiled Python apps with Instana]]></title>
            <link>https://medium.com/ibm-cloud/monitoring-compiled-python-apps-with-instana-4623344938d2?source=rss-d879af208b34------2</link>
            <guid isPermaLink="false">https://medium.com/p/4623344938d2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[instana]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[openshift]]></category>
            <category><![CDATA[ibm]]></category>
            <dc:creator><![CDATA[Cagri Yonca]]></dc:creator>
            <pubDate>Mon, 02 Nov 2026 19:38:58 GMT</pubDate>
            <atom:updated>2026-11-02T19:38:58.825Z</atom:updated>
            <content:encoded><![CDATA[<p>You can monitor a PyInstaller-compiled Python application with Instana by embedding the sensor directly in the binary. This article explains why standard zero-code instrumentation does not work in compiled binaries and shows three approaches tested against Instana 3.20.0 and PyInstaller 6.22 that restore full tracing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q7NJemXMk3m7ct84" /></figure><h3>Background</h3><p>When you compile a Python microservice with PyInstaller, the resulting binary runs an embedded CPython interpreter. Standard zero-code Instana instrumentation relies on PYTHONPATH, sitecustomize.py, .pth files (AUTOWRAPT_BOOTSTRAP=instana), or an admission webhook that sets these values for you. The embedded interpreter ignores all of these hooks. As a result, your traces disappear after you compile the app.</p><p>This is not a bug in Instana or PyInstaller. import instana works correctly inside a compiled binary. Three approaches restore the sensor, each suited to a different situation:</p><ul><li>Approach 1: Add import instana to your source code and build normally.</li><li>Approach 2: Use a PyInstaller runtime hook so you do not need to modify app.py.</li><li>Approach 3: Deploy the runtime-hook binary to OpenShift or Kubernetes without the AutoTrace webhook.</li></ul><h3>How PyInstaller works</h3><p>PyInstaller follows all import statements in your code statically, compiles the referenced modules to bytecode, and stores them in a PYZ archive. The build packages that archive, the shared libraries (including libpython3.x.so), and any declared data files into a PyInstaller-specific CArchive appended to a small bootloader executable. At runtime in onefile mode, the sequence is:</p><ol><li>The bootloader extracts the shared libraries, data files, and base_library.zip (the stdlib modules required for bootstrapping) into a temporary directory (/tmp/_MEIxxxxxx).</li><li>The bootloader loads libpython3.x.so from that directory with dlopen and starts the interpreter. PyInstaller does not extract your Python modules, a custom sys.meta_path importer reads them directly from the PYZ archive inside the executable.</li><li>Runtime hooks run, and then your __main__ runs — inside a full CPython interpreter.</li></ol><blockquote><strong><em>Key insight</em></strong><em>: CPython itself is still running inside the binary. </em><em>import still works. What changes is where modules come from and which startup hooks the interpreter accepts.</em></blockquote><h4>What the compiled interpreter ignores</h4><p>A PyInstaller binary starts Python with the equivalent of -S -E: the interpreter ignores PYTHONPATH, does not import site, never executes sitecustomize.py, and never processes .pth files — so AUTOWRAPT_BOOTSTRAP=instana has no effect. None of the out-of-process activation paths reach the interpreter. The fix is to bring import instana into the binary.</p><h4>Which libraries Instana can instrument in a compiled binary</h4><p>PyInstaller’s analyzer follows the import chain recursively from your entry point, including imports inside functions and inside try/except ImportError blocks. Instana&#39;s boot_agent() imports every instrumentation module with ordinary from instana.instrumentation import ... statements, and each of those modules performs a plain import flask, import urllib3, and so on. PyInstaller therefore detects the whole chain without additional configuration:</p><pre>app.py<br> ├── import instana                 → instana/__init__.py<br> │    └── boot_agent()<br> │         ├── instana.instrumentation.flask    → import flask    → Flask bundled<br> │         ├── instana.instrumentation.urllib3  → import urllib3  → urllib3 bundled<br> │         └── instana.instrumentation.werkzeug → import werkzeug → werkzeug bundled<br> └── from flask import Flask   (already in bundle from above)</pre><p>A plain pyinstaller app.py with import instana in the code bundles all instana.instrumentation.* submodules. Confirm this with:</p><pre>pyi-archive_viewer -l -r dist/app | grep instana.instrumentation</pre><p>This has two consequences:</p><ul><li>Instana can instrument only libraries present in the bundle. If a library is not installed in the build environment, its instrumentation module imports nothing, and PyInstaller lists it as “missing” in build/&lt;name&gt;/warn-&lt;name&gt;.txt. This is expected and harmless.</li><li>Build in a clean virtual environment. Because Instana’s instrumentation modules try to import many libraries, anything installed in the build environment that Instana references ends up in the binary, whether your app uses it or not.</li></ul><blockquote><strong><em>Note</em></strong><em>: PyInstaller collects modules automatically, but PyInstaller bundles non-Python files that a package reads at runtime (</em><em>.css, </em><em>.html, </em><em>.json, templates, and similar) only if a PyInstaller hook declares them. Hooks exist for many popular packages; for the rest, you get a </em><em>FileNotFoundError at runtime. Fix this by passing </em><em>--collect-data &lt;package&gt; on the command line, or by using </em><em>collect_data_files(&quot;&lt;package&gt;&quot;) in a spec file. The </em><em>instana package itself ships no data files.</em></blockquote><h3>The base application</h3><p>All three approaches in this article use the same minimal Flask app:</p><pre># app.py — pure application code, zero instrumentation<br>from flask import Flask, jsonify<br><br>app = Flask(__name__)<br><br>@app.route(&quot;/&quot;)<br>def index():<br>    return jsonify({&quot;status&quot;: &quot;ok&quot;})<br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(host=&quot;0.0.0.0&quot;, port=8080, debug=False)</pre><p>Set up a clean virtual environment before building:</p><pre>python -m venv .venv<br>source .venv/bin/activate<br>pip install flask instana pyinstaller</pre><h3>Approach 1: Manual instrumentation — import instana in source</h3><p>Manual instrumentation is the most direct approach. You add one line to the application source and build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ESjfsZdSbZUy1TP7" /></figure><h4>Step 1 — Add import instana to source</h4><p>Create app_manual.py — identical to app.py with one line prepended:</p><pre>+ import instana<br>  from flask import Flask, jsonify<br>  ...</pre><p>Add the import first. Some libraries tolerate being imported before Instana; others retain a reference to the unpatched symbol if you import them first. Importing Instana first avoids that entire class of problems.</p><h4>Step 2 — Build</h4><p>You do not need a spec file, a hiddenimports list, or collect_all(&quot;instana&quot;). PyInstaller&#39;s static analysis finds every instrumentation module automatically. Use --hidden-import only if warn-*.txt or a runtime ModuleNotFoundError shows that a module your app uses was missed.</p><pre>pyinstaller app_manual.py --onefile --name app_manual \<br>  --distpath instana_manual/dist --workpath instana_manual/build</pre><h4>Step 3 — Verify</h4><pre>INSTANA_DEBUG=true \<br>INSTANA_AGENT_HOST=localhost \<br>INSTANA_AGENT_PORT=42699 \<br>INSTANA_SERVICE_NAME=flask-binary-manual \<br>./instana_manual/dist/app_manual</pre><p>The startup log confirms activation:</p><pre>Stan is on the scene.  Starting Instana instrumentation version: 3.20.0<br>Instrumenting asyncio<br>Instrumenting flask (with blinker support)<br>Instrumenting logging<br>Instrumenting urllib3<br>Instrumenting werkzeug<br> * Serving Flask app &#39;app_manual&#39;<br> * Running on http://127.0.0.1:8080</pre><p>After the agent becomes reachable and requests arrive, you also see:</p><pre>Agent is ready.  Getting to work.<br>Reporting N spans</pre><p><strong>When to use this approach</strong>: You own the source code and can modify it, and you want the most explicit and verifiable setup.</p><h3>Approach 2: Zero-code-change — runtime hook</h3><p>This approach produces the same result as Approach 1 without modifying app.py. PyInstaller runtime hooks are Python files that the compiled binary executes before __main__ runs.</p><p>The execution order inside the binary:</p><pre>Binary launched<br>  └── bootloader starts the embedded interpreter<br>      └── runtime hooks execute<br>          └── instana_hook.py  →  import instana  →  patches Flask, urllib3, werkzeug<br>      └── __main__ starts  (app.py — unmodified)<br>          └── from flask import Flask  ← already patched</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jdLrK7bWr91b_bkA" /></figure><h4>Step 1: The hook file</h4><p>instana_auto/instana_hook.py contains a single line. The hook file is the single source of truth for &quot;this binary has Instana&quot;. PyInstaller analyzes runtime hooks like any other script, so everything import instana pulls in is bundled automatically.</p><pre># Executed by PyInstaller before __main__. app.py is never modified.<br>import instana</pre><h4>Step 2: Build</h4><pre>pyinstaller app.py --onefile --name app_auto \<br>  --runtime-hook instana_auto/instana_hook.py \<br>  --distpath instana_auto/dist --workpath instana_auto/build</pre><h4>Step 3: Verify</h4><pre>INSTANA_DEBUG=true \<br>INSTANA_AGENT_HOST=localhost \<br>INSTANA_AGENT_PORT=42699 \<br>INSTANA_SERVICE_NAME=flask-binary-auto \<br>./instana_auto/dist/app_auto</pre><p>The startup log shows the same Instrumenting ... lines as Approach 1, with one telling difference:</p><pre>* Serving Flask app &#39;app&#39;   ← &#39;app&#39;, not &#39;app_manual&#39; — app.py is the entry point</pre><p>Confirm that app.py is unmodified:</p><pre>grep -n &quot;instana&quot; app.py<br># (no output — app.py contains no reference to instana)</pre><p><strong>When to use this approach</strong>: You cannot or should not modify the application source code, and you want to control instrumentation at build time rather than in code.</p><h3>Approach 3: OpenShift deployment — no AutoTrace webhook</h3><p>For OpenShift or Kubernetes, you use the same runtime-hook build as Approach 2. Two things change in this configuration: the binary uses onedir mode, and you package it in a container image. You do not need a webhook, an init container, sitecustomize.py, or PYTHONPATH manipulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p9J5aDo7RtxCXK1M" /></figure><h4>Why the AutoTrace webhook does not apply here</h4><p>The Instana AutoTrace webhook adds instrumentation to Python containers at deployment time by injecting code from outside the application. A PyInstaller binary ignores PYTHONPATH, never imports site, and never runs sitecustomize.py or .pth files — so any injection that relies on the interpreter picking up environment code cannot activate the sensor in a compiled binary.</p><p>You do not need the webhook: the runtime-hook binary already contains Instana. The webhook does not check the process type. By default, it works in opt-out mode and injects an init container into every container in every pod. The compiled binary ignores that injection, so it is harmless, but it is also unnecessary. To keep the pod clean, set the label instana-autotrace: &quot;false&quot; on the workload. This label excludes the resource from injection in every webhook configuration. If the webhook was installed with autotrace.opt_in=true, it instruments only resources labeled instana-autotrace: &quot;true&quot;, so you can also omit the label in that case.</p><h4>Container build — onedir mode</h4><p>For containers, prefer onedir over onefile:</p><ul><li>onefile extracts its shared libraries and data files into a new _MEIxxxxxx directory under $TMPDIR (default /tmp) on every start. This costs startup time and fails if the container has no writable temporary directory — for example, with readOnlyRootFilesystem: true and no emptyDir mounted at /tmp. If $TMPDIR is not writable, the bootloader falls back to /tmp, so the failure occurs only when /tmp is not writable either.</li><li>onedir produces an executable plus an _internal/ directory that the binary uses in place at runtime — PyInstaller extracts nothing at startup.</li></ul><p>instana_auto/app_openshift.spec:</p><pre>import os<br><br>SPEC_DIR = os.path.dirname(os.path.abspath(SPEC))<br>ROOT_DIR = os.path.dirname(SPEC_DIR)<br><br>a = Analysis(<br>    [os.path.join(ROOT_DIR, &quot;app.py&quot;)],<br>    pathex=[ROOT_DIR],<br>    runtime_hooks=[os.path.join(SPEC_DIR, &quot;instana_hook.py&quot;)],<br>)<br>pyz = PYZ(a.pure)<br><br># onedir: EXE excludes binaries, COLLECT gathers everything into dist/app/<br>exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name=&quot;app&quot;, console=True)<br>coll = COLLECT(exe, a.binaries, a.datas, name=&quot;app&quot;)</pre><p>The build produces dist/app/app plus dist/app/_internal/.</p><p>The Dockerfile copies a requirements.txt file that pins the build dependencies:</p><pre>flask==3.1.1<br>instana==3.20.0<br>pyinstaller==6.22.3</pre><p>Pin the versions you tested with so that the build is reproducible.</p><p>Multi-stage Dockerfile:</p><pre># Stage 1: build the compiled binary on the same OS family as the runtime image.<br># PyInstaller bundles libpython and other shared libraries from the build<br># image; they must not require a newer glibc than the runtime image provides.<br>FROM registry.access.redhat.com/ubi9/python-312 AS builder<br><br>WORKDIR /opt/app-root/src<br>COPY requirements.txt .<br>RUN pip install --no-cache-dir -r requirements.txt<br><br>COPY app.py .<br>COPY instana_auto/app_openshift.spec ./instana_auto/app_openshift.spec<br>COPY instana_auto/instana_hook.py    ./instana_auto/instana_hook.py<br>RUN pyinstaller instana_auto/app_openshift.spec \<br>    --distpath dist --workpath build --noconfirm<br><br># Stage 2: minimal runtime image - no Python, no pip, no venv<br>FROM registry.access.redhat.com/ubi9/ubi-minimal<br>WORKDIR /app<br>COPY --from=builder /opt/app-root/src/dist/app /app<br><br>USER 1001<br>EXPOSE 8080<br>CMD [&quot;/app/app&quot;]</pre><p>Why not python:3.12-slim as the builder? That image is based on Debian bookworm (glibc 2.36), while UBI 9 ships glibc 2.34. PyInstaller binaries require a build environment with the same or older glibc as the target; a newer glibc causes the binary to fail at startup with GLIBC_2.3x not found. Building on a UBI 9 image avoids the mismatch. PyInstaller requires objdump from binutils on Linux; the ubi9/python-312 builder image ships a compiler toolchain, but if objdump is missing, add the following before the build step:</p><pre>USER 0<br>RUN dnf install -y binutils<br><br>USER 1001</pre><h4>Deployment manifest</h4><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: flask-binary-auto<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: flask-binary-auto<br>  template:<br>    metadata:<br>      labels:<br>        app: flask-binary-auto<br>        # Exclude this workload from AutoTrace webhook injection<br>        instana-autotrace: &quot;false&quot;<br>    spec:<br>      containers:<br>        - name: flask-binary-auto<br>          image: &lt;registry&gt;/flask-binary-auto:latest<br>          ports:<br>            - containerPort: 8080<br>          env:<br>            - name: INSTANA_AGENT_HOST<br>              valueFrom:<br>                fieldRef:<br>                  fieldPath: status.hostIP   # the agent on this pod&#39;s node<br>            - name: INSTANA_AGENT_PORT<br>              value: &quot;42699&quot;<br>            - name: INSTANA_SERVICE_NAME<br>              value: &quot;flask-binary-auto-openshift&quot;</pre><p>status.hostIP resolves to the IP of the node the pod runs on, where the Instana agent DaemonSet listens — no hard-coded address required.</p><blockquote><strong><em>Note</em></strong><em>: </em><em>INSTANA_AGENT_HOST=localhost does not reach a host-side agent from inside a container. On macOS and Windows, use </em><em>host.docker.internal. On Linux, use the Docker bridge gateway (usually </em><em>172.17.0.1).</em></blockquote><h4>Verification</h4><p>After oc apply, the pod log shows the same activation sequence — now inside a container, without any cluster-level assistance:</p><pre>Stan is on the scene.  Starting Instana instrumentation version: 3.20.0<br>Instrumenting flask (with blinker support)<br>...<br>Agent is ready.  Getting to work.</pre><p>Confirm that no init container was injected:</p><pre>oc get pod -l app=flask-binary-auto \<br>  -o jsonpath=&#39;{.items[0].spec.initContainers}&#39;<br># (empty — the instana-autotrace: &quot;false&quot; label excluded the pod from injection)</pre><p>If the output is not empty, check that the instana-autotrace: &quot;false&quot; label is present on the pod template, not only on the Deployment object.</p><p><strong>When to use this approach</strong>: You are deploying a PyInstaller binary to Kubernetes or OpenShift and want the simplest possible agent connection — no webhook dependency and no cluster-level configuration changes.</p><h3>Comparison</h3><p>The following table summarizes the three approaches:</p><p>Approach 1Approach 2Approach 3Source changeimport instana addedNoneNoneBuildpyinstaller --onefile app_manual.py+ --runtime-hook instana_hook.pyRuntime hook + onedir specSpec fileOptionalOptionalUsed (onedir)Hook file—import instana (1 line)SameContainer build——Multi-stage, UBI 9 builder + UBI 9 minimalAgent addresslocalhostlocalhoststatus.hostIP fieldRefAutoTrace webhook——Excluded with instana-autotrace: &quot;false&quot;</p><h3>Troubleshooting</h3><p>Use this section to diagnose and fix common problems with PyInstaller builds and Instana instrumentation.</p><h4>Script not found during build</h4><p><strong>Cause</strong>: The spec file uses a relative path and you invoked PyInstaller from a different working directory.</p><p><strong>Fix</strong>: Use the SPEC built-in variable to anchor paths:</p><pre>SPEC_DIR = os.path.dirname(os.path.abspath(SPEC))<br>ROOT_DIR = os.path.dirname(SPEC_DIR)<br><br>a = Analysis([os.path.join(ROOT_DIR, &quot;app.py&quot;)], ...)</pre><h4>No “Stan is on the scene” line at startup</h4><p><strong>Cause</strong>: The binary never imported Instana. Common reasons: the build relied on PYTHONPATH, sitecustomize.py, AUTOWRAPT_BOOTSTRAP, or the AutoTrace webhook — all of which the compiled binary ignores — or you did not pass the runtime hook to the build.</p><p><strong>Fix</strong>: Use Approach 1 or Approach 2. Check that INSTANA_TRACING_DISABLE is not set. This variable turns the sensor off completely, and the binary then produces no Instana output. The older INSTANA_DISABLE variable is deprecated: in version 3.20.0 it only prints a DeprecationWarning and does not stop the sensor.</p><h4>Sensor starts, but “Instrumenting flask” is missing</h4><p>Check the following:</p><ul><li>INSTANA_DISABLE_AUTO_INSTR must not be set at all. The sensor checks only whether the variable exists, not its value, so even INSTANA_DISABLE_AUTO_INSTR=false disables automatic instrumentation.</li><li>The library must be present in the bundle: pyi-archive_viewer -l -r dist/&lt;binary&gt; | grep flask. If it is missing, either the library was not installed in the build environment or nothing in the entry point imports it. Install it in the build virtual environment or, as a last resort, add --hidden-import &lt;module&gt;.</li></ul><h4>Sensor activates but no spans appear</h4><p>Check the debug log for:</p><pre>Instana Host Agent couldn&#39;t be found. Will retry periodically...<br>Instana Host Agent not found on &lt;host&gt;:42699</pre><p><strong>Fix</strong>: The binary cannot reach the agent. Set INSTANA_AGENT_HOST and INSTANA_AGENT_PORT correctly (status.hostIP on Kubernetes — see the Docker note in Approach 3) and check network policies between the pod and port 42699 on the node.</p><h4>FileNotFoundError for a .css, .json, or .html file at startup</h4><p><strong>Cause</strong>: A bundled dependency reads a non-Python data file at runtime and no PyInstaller hook declares it.</p><p><strong>Fix</strong>: Pass --collect-data affected_package on the command line, or add the following to a spec file:</p><pre>from PyInstaller.utils.hooks import collect_data_files<br><br>a = Analysis(..., datas=collect_data_files(&quot;affected_package&quot;))</pre><h4>ModuleNotFoundError at startup</h4><p><strong>Cause</strong>: A module is imported in a way that static analysis cannot detect — for example, via importlib.import_module(name) with a computed name, or through a plugin system.</p><p><strong>Fix</strong>: Look up the missing module in build/&lt;name&gt;/warn-&lt;name&gt;.txt, then add --hidden-import &lt;module&gt; (or hiddenimports=[...] in the spec). For a package with many such modules, use --collect-submodules &lt;package&gt; or --collect-all &lt;package&gt;.</p><h4>Binary fails with “GLIBC_2.xx not found”</h4><p><strong>Cause</strong>: You built the binary on a newer Linux than the target system runs.</p><p><strong>Fix</strong>: Build on the oldest OS version you target — ideally the same base image family as the runtime image (see the Dockerfile in Approach 3).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4623344938d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ibm-cloud/monitoring-compiled-python-apps-with-instana-4623344938d2">Monitoring compiled Python apps with Instana</a> was originally published in <a href="https://medium.com/ibm-cloud">IBM Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fetching Data from Twitter to MongoDB]]></title>
            <link>https://medium.com/i%CC%87stanbuldatascienceacademy/fetching-data-from-twitter-to-mongodb-9cbf55a24361?source=rss-d879af208b34------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cbf55a24361</guid>
            <category><![CDATA[tweepy]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Cagri Yonca]]></dc:creator>
            <pubDate>Mon, 17 Jan 2022 16:48:16 GMT</pubDate>
            <atom:updated>2022-01-18T10:12:33.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5wY4SCcGqNTkZnti" /><figcaption>Photo by <a href="https://unsplash.com/@shwetha?utm_source=medium&amp;utm_medium=referral">Shwetha Shankar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello everybody ✌️. I’m here to take your 15 or 20 minutes to do a quick presentation for Twitter Data Streaming if you want to learn of course 😄</p><h3><strong>Before Starting</strong></h3><p>In this project, we will follow the workflow below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*8Yn1mIPHywo5BzSt7C4Ixw.png" /></figure><p>Version information for modules we used,</p><ul><li><a href="https://pypi.org/project/tweepy/">Tweepy</a> v4.4.0</li><li><a href="http://pip install pymongo">PyMongo</a> v4.0.1</li><li><a href="https://pypi.org/project/pandas/">Pandas</a> v1.3.4</li><li><a href="https://pypi.org/project/notebook/">Jupyter Notebook</a> v6.4.5</li></ul><p>You should be installed these modules with corresponding versions.</p><p>Secondly, in order to fetch Tweets, we need a developer account. You can apply for a developer account on <a href="https://developer.twitter.com/en/portal/dashboard">this</a> page. I’ve applied as a student because I’m trying to learn how this service works and after application, they sent me an email to know more about the purpose of usage. After I explained this project they opened my account in 3–4 days.</p><p>Lastly, to write the data we collect, we need a database on MongoDB. Go to <a href="https://www.mongodb.com/cloud/atlas/register">this</a> page and create a new account if you don’t have, yet. You can follow the first 11 min of <a href="https://www.youtube.com/watch?v=S4fi6Qux-4g&amp;t=2043s">this</a> video to create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DhfCjt1IRODHbe5s" /></figure><h3><strong>start_engine()</strong></h3><p>Let’s start with preparing tokens for connections with Twitter and MongoDB.</p><p><strong>Getting Twitter Connection Keys</strong></p><ul><li>Go to <a href="https://developer.twitter.com/en/portal/projects-and-apps">Projects &amp; Apps</a> section at Twitter Developer Portal.</li><li>Create a new application, you need to give it a unique name.</li><li>After creating your application, it will give you 4 different tokens as <strong>API Key</strong>, <strong>API Secret</strong>, <strong>Access Token</strong> and <strong>Access Secret</strong>. Note them somewhere.</li></ul><p><strong>Getting MongoDB Connection Keys</strong></p><ul><li>Create a project and a cluster into it. Wait a little bit, creating a new cluster takes a while.</li><li>Click to <strong>Connect</strong> button of the cluster and select ‘Connect your application’.</li><li>Select your Python version (you can use `python --version` command in the terminal) and copy the connection string in second section. Note it to the same place you used before, don’t forget to change <strong>&lt;password&gt;</strong> of the string with your actual MongoDB password.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C-VMbaHGzzvNgfoW" /></figure><h3><strong>drive()</strong></h3><p>Now we are starting to code. Just start with basic imports:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*Yi0vY-1iNuDAygUlc1hhag.png" /></figure><p>Then set tokens we will use, don’t share your secret keys with anyone:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*eFoCMIZespEa-N1_9ztRug.png" /></figure><p>Now we need a connection client to MongoDB, we gonna create a connection pipe with this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*V28I4PNaZ4fbKsGJmIivXg.png" /></figure><p>You need to change ‘connection string’ with your own. In the second line, we are creating a new database named ‘demo’ and a collection named tweet_collection in the third line. Lastly, we are creating an index named id on our tweet collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*Xg9KqMtPkn3dh78K4uHVBA.png" /></figure><p>Now we are defining a listener class to listening to Twitter API and fetching data. This stream can be improved by adding more functionalities and preprocessing units there. Tweepy’s Stream class has its own built-in methods such as on_closed, on_connect, on_connection_error, on_data, etc. So it would be better if you know these states of the stream object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*p0TiURRHJQPE5QuW1P5vvA.png" /></figure><p>When you run this cell, stream will start to fetch tweets immediately and it will keep fetching until you stop it. MongoDB’s free edition gives us limited storage to store data so it would be better if you stop it after 25–30 seconds. In the second line, it is filtering the data as you see, we are looking for ‘bbc’ keyword in tweets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*Y63yGZCUsbKXq6K3BdxtZA.png" /></figure><p>These two can be used to see the number of tweets and the number of distinct users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*-xts4q7AMDPLEpJ3KJ6wiA.png" /></figure><p>We are creating an index to search faster at our collection, the ‘text’ parameter is the key name that is coming from Twitter API. You can check the incoming keys <a href="https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*XNqcEs__xX2k-KYx-VBL6g.png" /></figure><p>Now we are creating a cursor list, this will find entities that include ‘covid’ string and append them into the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*DYztFVGoWiWOwKkzKWpI1Q.png" /></figure><p>We can briefly print the cursor data like this. This is the endpoint of this streaming pipeline so you can use this data anywhere you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qMTh5Fk5LpV1hf-s" /></figure><h3><strong>stop_and_park()</strong></h3><p>Now we have our tweet data here. You can use any tool or processing method you want. We won’t do anything detailed with Pandas but I wanted to show you one more thing. You can use the data directly through the Pandas as you see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*s295-MJy6upbj78hNkXkgA.png" /></figure><h3><strong>Conclusion</strong></h3><p>Collecting data and preparing data pipelines are really important jobs these days. For a data engineer, data streaming is one of the most required skills to prepare data to work on it. There is a lot of different data API other than Twitter, such as CoinMarketCap for cryptocurrency, Facebook for FB posts, YouTube for YT videos. I’ll try to use and explain different APIs in the next weeks so see you all next time 🤞</p><p><strong>References</strong></p><p><a href="https://www.guru99.com/working-mongodb-indexes.html">https://www.guru99.com/working-mongodb-indexes.html</a></p><p><a href="https://www.geeksforgeeks.org/python-mongodb-create_index-query/">https://www.geeksforgeeks.org/python-mongodb-create_index-query/</a></p><p><a href="https://www.youtube.com/watch?v=rm0mJP1P4eE">https://www.youtube.com/watch?v=rm0mJP1P4eE</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cbf55a24361" width="1" height="1" alt=""><hr><p><a href="https://medium.com/i%CC%87stanbuldatascienceacademy/fetching-data-from-twitter-to-mongodb-9cbf55a24361">Fetching Data from Twitter to MongoDB</a> was originally published in <a href="https://medium.com/i%CC%87stanbuldatascienceacademy">İstanbul Data Science Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Atik / Çevik / Agile]]></title>
            <link>https://cagriyonca.medium.com/atik-%C3%A7evik-agile-5da7473890e9?source=rss-d879af208b34------2</link>
            <guid isPermaLink="false">https://medium.com/p/5da7473890e9</guid>
            <category><![CDATA[atik]]></category>
            <category><![CDATA[çevik]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[agile-methodology]]></category>
            <category><![CDATA[çevik-yazılım-geliştirme]]></category>
            <dc:creator><![CDATA[Cagri Yonca]]></dc:creator>
            <pubDate>Wed, 25 Aug 2021 18:27:10 GMT</pubDate>
            <atom:updated>2022-10-21T07:29:04.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Eb3qIgUalzpBZf41" /></figure><h3>Önsöz</h3><p>İlk olarak şunu bir çözelim, bu yazıda Agile kelimesinin karşılığı olarak genel kullanımın aksine Çevik yerine Atik kelimesini kullandım. Tamamen kişisel düşüncem Çevik kelimesinin zihnimde Agile felsefesi ile bağdaşmamasıdır. Benim için Atik kelimesi hızlı davranan, değişim ve yeniliğe açık, ve zihnimde Atik’liğin kendinden gelen kısa, yenilikçi, basit ve öz şeyleri çağrıştırdığı için, ayrıca Çevik kelimesinin zihnimde nispeten daha güçlü, dayanıklı, atik olan nesnelere kıyasla hantal ve yavaş nesneleri çağrıştırmasından dolayı Agile kelimesini Atik olarak kullanıyorum ve Çevik kelimesinin uyumsuzluğundan hepinizi kurtarıyorum.</p><p>Bu konuyla alakalı arkadaşıma sorduğum soruyu size de soruyorum:</p><p>İçi gözükmeyen bir kutunun içinde hareketli bir nesne var, hızlı hızlı hareket ediyor, kolayca şekil değiştirebiliyor, sık sık kutuda bir yere çarpıp dışarı çıkmaya çalışıyor. Bu kutunun içindeki objeyi Atik olarak mı nitelendirirsiniz, yoksa Çevik olarak mı? Lütfen cevabınız hala çevik ise yorumlarda belirtin.</p><p>İkincil olarak bu yazı tamamen <a href="https://agilemanifesto.org/iso/tr/manifesto.html">agilemanifesto.org</a> sitesindeki Türkçe çevirinin tam anlamını karşılamadığı düşüncesiyle oluşturulmuştur.</p><p>Şu anda kullanılan tam anlamını karşılamadığını düşündüğüm çeviriye <a href="https://agilemanifesto.org/iso/tr/manifesto.html">buraya</a>(manifesto) ve <a href="https://agilemanifesto.org/iso/tr/principles.html">buraya</a>(12 temel prensip) tıklayarak ulaşabilirsiniz.</p><h3>Atik Yazılım Geliştirmek için Manifesto</h3><p>Yazılım geliştirerek ve başkalarına yardımcı olarak, geliştirmenin daha iyi yönlerini bulmaya çalışıyoruz. Bu vazifemiz neticesinde:</p><p>İşlemler ve araçlardan ziyade <strong>bireyler ve etkileşimlere</strong>,</p><p>Kapsamlı dökümantasyonlardan ziyade <strong>çalışan yazılımlara,</strong></p><p>Sözleşme görüşmelerinden ziyade <strong>müşteriyle iş birliğine,</strong></p><p>Plana bağlı kalmaktan ziyade <strong>değişime ayak uydurmaya,</strong></p><p>değer vermeye başladık.</p><p>Yani, eskiden sağdakiler zaten değerliyken, soldakileri daha değerli buluyoruz.</p><h3>Atik Manifestonun Ardındaki Prensipler</h3><p>Bizler aşağıdaki prensipleri takip ediyoruz:</p><ul><li>En büyük önceliğimiz değerli yazılımın müşteriye erken ve sürekli ulaşımını sağlamaktır.</li><li>Geliştirmenin sonunda bile isteklerin değişimi hoş karşılanmalıdır. Atik süreçler müşterinin rekabet avantajı için değişiminden yararlanır.</li><li>Çalışan bir uygulama, birkaç haftadan birkaç aya kadar, kısa zaman aralıklarıyla sürekli olarak müşteriye teslim edilmelidir.</li><li>İş adamları ve geliştiriciler proje süresince günlük olarak beraber çalışmalıdır.</li><li>Projeler motive bireylerin etrafında inşa edilmelidir. İhtiyaçları olan gereksinimler ve destek verilmeli, işi bitirebileceklerine güvenilmelidir.</li><li>Bir geliştirici takımına bilgi paylaşırken ve takımın kendi içerisinde, en verimli ve etkili bilgi paylaşım yöntemi yüz yüze görüşmedir.</li><li>İlerlemenin birincil ölçütü çalışan yazılımdır.</li><li>Atik süreçler sürdürülebilir gelişimi teşvik eder. Sponsorlar, geliştiriciler ve kullanıcılar sabit bir tempoyu koşulsuz şartsız sürdürebilmelidir.</li><li>Teknik mükemmelliğe ve iyi tasarıma sürekli özen göstermek atikliği geliştirir.</li><li>Basitlik (yapılmayan iş miktarını maksimize etme sanatı) esastır.</li><li>En iyi mimariler, istekler ve tasarımlar kendini iyi organize edebilen takımlardan ortaya çıkar.</li><li>Takım düzenli aralıklarla nasıl daha etkili olabileceğini düşünür, ardından davranışlarını buna gore uyarlar ve düzeltir.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5da7473890e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brief Comparison of Ansible and Chef]]></title>
            <link>https://cagriyonca.medium.com/brief-comparison-of-ansible-and-chef-cc72d2a88b89?source=rss-d879af208b34------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc72d2a88b89</guid>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[chefs]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[comparison]]></category>
            <dc:creator><![CDATA[Cagri Yonca]]></dc:creator>
            <pubDate>Fri, 13 Aug 2021 21:46:54 GMT</pubDate>
            <atom:updated>2021-08-13T21:46:54.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TIH7pr7zOJejoFD9" /><figcaption>Photo by <a href="https://unsplash.com/@sanderweeteling?utm_source=medium&amp;utm_medium=referral">Sander Weeteling</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is Configuration Management?</h3><p>Configuration management came about to address the fundamental challenges involved in doing group work. Managing change when you are a lone administrator with a handful of servers to manage is relatively straightforward.</p><h3>Why we need a Configuration Management Tool to Automate IT?</h3><p>There are four main reasons to use Management Tools:</p><ul><li><strong>Consistency.</strong> You may want to be sure about if your servers are set up in a consistent manner.</li><li><strong>Efficient change management. </strong>When an organization want to develop processes for managing changes.</li><li><strong>Simplicity in rebuild. </strong>If you need to rebuild servers manually, it will be very challenging with a management tool.</li><li><strong>Visibility. </strong>Configuration management tools include auditing and reporting capabilities. For one administrator, this issue will not be a big problem but if you are trying to understand what is going on for 10 system administrators you will need a configuration tool.</li></ul><h3><strong>What is Chef?</strong></h3><p>Chef is an automation platform that configures and manages your infrastructure. Whether you are operating in the cloud, on-premises, or in a hybrid environment, Chef automates how infrastructure is configured, deployed, and managed across your network.</p><ul><li>Your infrastructure is versionable.</li><li>Your infrastructure is repeatable.</li><li>Your infrastructure is testable.</li></ul><h3>What is Ansible?</h3><p>Ansible is an open source tool which you can automate cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs. It’s open source but has also paid services like <a href="https://www.ansible.com/products/tower">Tower</a> to visualize data on dashboard.</p><h3>Ansible vs Chef</h3><p>There are a lot of differences between these two tools. We will look at to differences now.</p><blockquote>Ansible calls its configuration files “playbooks”, while Chef calls them “cookbooks”.</blockquote><p>Ansible’s playbooks are not complex to create but you have Python’s limitations to make complex tasks. Chef’s cookbooks can be thought like bash scripts, you can do more complex jobs.</p><blockquote>Ansible uses a master running on the server machine, it doesn’t require any agent to connect from client machine. It uses SSH connection to do operations. Chef operates with a master-client architecture. The server part runs on the master machine, while the client portion runs as an agent on client machine.</blockquote><p>This makes Ansible faster than Chef to run commands on master.</p><blockquote>Ansible’s source of truth comes from its deployed playbooks, which are perfect as source control systems, while Chef relies on its own server as the source of truth, and those servers require uploaded cookbooks which means making sure the latter are consistent and identical.</blockquote><p>Ansible is just more easier and useful.</p><blockquote>Ansible uses YAML to manage configurations, while Chef is using Ruby DSL configuration scripts for server.</blockquote><p>No comment, YAML vs Ruby DSL.. Choose which one is easier for you.</p><p>Chef’s Ruby DSL is awesome for teams who works Ruby for their actual works.</p><p>If you have a complex cloud deployment across platforms such as Amazon, Google Cloud, Azure and OpenStack with regular schedules for server updates, Chef is great option.</p><h3>Conclusion</h3><p>If you need to do complex tasks and know Ruby, use Chef, otherwise I’d choose Ansible which is more easier to use and develop.</p><p>Please leave comments, I’d be pleased to make these articles better.</p><blockquote>References</blockquote><ul><li><a href="https://learning.oreilly.com/library/view/learning-chef/9781491945087/">Learning Chef</a></li><li><a href="https://www.upguard.com/blog/ansible-vs-chef">Ansible vs Chef Updated for 2020 [Infographic] | UpGuard</a></li><li><a href="https://www.simplilearn.com/ansible-vs-chef-differences-article">Ansible vs Chef: What&#39;s the Difference?</a></li><li><a href="https://careerkarma.com/blog/ansible-vs-chef/">Ansible vs Chef: The Key Differences</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc72d2a88b89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How long would it take to think like human?]]></title>
            <link>https://cagriyonca.medium.com/how-long-would-it-take-to-think-like-human-e8de6fdff171?source=rss-d879af208b34------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8de6fdff171</guid>
            <category><![CDATA[generative-adversarial]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[gpt-3]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Cagri Yonca]]></dc:creator>
            <pubDate>Thu, 12 Aug 2021 16:03:09 GMT</pubDate>
            <atom:updated>2021-08-16T11:28:58.742Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mrVyhzIcXPxs9q_w" /><figcaption>Photo by <a href="https://unsplash.com/@ankitsood?utm_source=medium&amp;utm_medium=referral">Ankit Sood</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Preface</h3><p>All we were excited about when OpenAI announced GPT-3 API with its use cases. Most of us may have thought like “If I train a model with the whole internet, I can create a model which knows anything that I ask it”. Let’s check out that what it is conceptually and how to use it.</p><blockquote><em>Not thinking but acting.</em></blockquote><h3>What is GPT-3?</h3><p>GPT means Generative Pre-Trained Transformer. It has built-in Natural Language Processor models so it can extract meaning from a text as we do. However, it has a difference from other NLP models, besides its NLP feature, it’s a generative model so it can generate linguistic data. It reads data, understands, learns, and uses it to answer your input.</p><blockquote><em>GPT-3 can talk to and understand you.</em></blockquote><h3>How to use GPT-3?</h3><p>GPT-3 is available as OpenAI’s private beta API by applying the waitlist form and is also a paid service. But there are also 2 open-source alternatives called GPT-J and GPT-Neo.</p><p>GPT-Neo has three different versions:</p><ul><li>125 million parameters</li><li>1.3 billion parameters</li><li>2.7 billion parameters</li></ul><p>There is only one version of GPT-J with 6 billion parameters, making it the most generative alternative to GPT-3.</p><h3>System Requirements to use GPT-J</h3><p>First we will talk about system requirements. There is no official information about that but according to <a href="https://www.reddit.com/r/MachineLearning/comments/oe6paj/d_gptj_for_text_generation_hardware_requirements/">this</a> guys post,</p><ul><li>On CPU, 40GBs of RAM for loading model, after it loaded it requires 20GBs of RAM during runtime.</li><li>On CPU, Standard text generation (around 50 words) requires 12 seconds for 12 CPUs</li><li>On GPU, the model needs 40GBs of RAM to load, and then around 3GBs of RAM during runtime + 24GBs of GPU memory</li><li>On GPU, Standard text generation (around 50 words) requires 1.5 seconds</li></ul><p>So before you start doing some staffing with GPT models, you need to fix the huge amount of RAM and GPU issues.</p><h3>How to use GPT-J?</h3><p>You can follow this <a href="https://colab.research.google.com/github/kingoflolz/mesh-transformer-jax/blob/master/colab_demo.ipynb#scrollTo=aO1UXepF-0Uq">Colab Notebook</a> to test it on the web (thanks to Google). I won’t show you the code but can show you what can you do with it, these and more can be found <a href="https://medium.com/predict/what-you-need-to-know-about-gpt-3-and-why-it-matters-4878215b78e8">here</a>:</p><ul><li>You can give some of a text about specific content and ask the model to write of the rest, it will try to write it with the narration style of the author.</li><li>AI-generated coding. <a href="https://minimaxir.com/2021/06/gpt-j-6b/">This</a> guy is giving the name of function and purpose of function as a command and the model tries to write it, and when he calls the same command again, the model tries to do the same functionality with different code.</li><li>You can generate images that never exist.</li><li>You can compose music that has never been composed.</li><li>You can create a chatbot that acts like a human.</li></ul><p>You should check <a href="https://medium.com/merzazine/about-humans-ai-and-god-1a7e7cf8e8cf">this</a> philosophic conversation with GPT-3 by <strong>Merzmensch</strong>.</p><h3>Epilogue</h3><p>In my opinion, this approach is just the beginning. We can generate but not extract humanistic mean from data. I’m not sure if we need it, but until we do, we’ll think we talking to a machine. Maybe someday we can link these models with sensors to get real world’s dynamic data and when they mix up with knowledge talking with a computer can come more realistic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8de6fdff171" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>